discourse/lib/site_settings
Martin Brennan 58797cef70
PERF: Improve performance of SiteSetting.humanize_name + all_settings (#34404)
Followup 5b236ccc07

The humanize_name method was introducing some slowness and also more
objects in memory to GC. This commit improves the performance by
memoizing and moving work to hash lookup instead of array.include?
checks, and making sure we compile regexes only once.

As well as this, we memoize the humanized names for all settings
so we don't have to recompute them every time we call all_settings.

Results are as follows:

**Current perf:**

```
Results:
Total time: 36.8178 seconds
Average time per call: 368.1783 ms
Calls per second: 2.72

Detailed timing:
User CPU time: 36.432 seconds
System CPU time: 0.2607 seconds
Total CPU time: 36.6926 seconds
Real time: 36.8178 seconds

Memory Report:
Total allocations: 10932505
Total retained: 985
```

**Humanize improvements:**

```
Results:
Total time: 27.7318 seconds
Average time per call: 277.3178 ms
Calls per second: 3.61

Detailed timing:
User CPU time: 27.3635 seconds
System CPU time: 0.2078 seconds
Total CPU time: 27.5713 seconds
Real time: 27.7318 seconds

Memory Report:
Total allocations: 5535404
Total retained: 1098
```

**Humanize improvements + memoization of humanized names:**

```
Results:
Total time: 24.5924 seconds
Average time per call: 245.9237 ms
Calls per second: 4.07

Detailed timing:
User CPU time: 24.2941 seconds
System CPU time: 0.2019 seconds
Total CPU time: 24.496 seconds
Real time: 24.5924 seconds

Memory Report:
Total allocations: 4417243
Total retained: 1184
```
2025-08-20 15:16:24 +10:00
..
db_provider.rb DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
defaults_provider.rb DEV: Fix various rubocop lints (#24749) 2023-12-06 23:25:00 +01:00
deprecated_settings.rb FEATURE: Themeable site settings (#32233) 2025-07-16 11:00:21 +10:00
hidden_provider.rb DEV: support un-hiding site settings programmatically (#32824) 2025-05-20 21:44:56 +02:00
label_formatter.rb PERF: Improve performance of SiteSetting.humanize_name + all_settings (#34404) 2025-08-20 15:16:24 +10:00
local_process_provider.rb DEV: Fix core backend CI tests timing out (#34281) 2025-08-13 16:06:19 +08:00
type_supervisor.rb FEATURE: Localize language names (#33790) 2025-07-29 11:48:45 +08:00
validations.rb DEV: Add setting to tag s3 objects enabling tag based access control policies (#32988) 2025-06-16 13:26:18 +08:00
yaml_loader.rb DEV: Remove older ruby version logic (#19971) 2023-01-24 10:42:56 +00:00