Skip to content

Optimize light configuration and caching#681

Open
bolshakov wants to merge 5 commits into
developfrom
feature/lights-cache
Open

Optimize light configuration and caching#681
bolshakov wants to merge 5 commits into
developfrom
feature/lights-cache

Conversation

@bolshakov
Copy link
Copy Markdown
Owner

@bolshakov bolshakov commented May 23, 2026

Improved System#light caching performance using pre-computed configuration digests and added better error messages with source locations.

  • Pre-compute digest during LightConfigurationDsl initialization
  • Implement #hash for traffic/recovery control strategies -- allows comparing configurations effectively
  • Cache UNDEFINED constant (saves Undefined.instance lookup overhead) - there is more room for improvement here, but it does not play well with RBS.
  • Improve configuration conflict errors. Previously error message included both configurations, not it includes both call sites.
  • Split DSL classes by use case
    • LightConfigurationDsl: Optimized for light caching with pre-computed digest
    • SystemConfigurationDsl: For system-level configuration
    • LegacyConfigurationDsl: For backward compatibility, used outside of system, will be removed eventually.

Performance impact

More effective lights cashing enabled a massive performance gain on light lookup.

ruby 3.2.4 (2024-04-23 revision af471c0e01) [arm64-darwin23]
Warming up --------------------------------------
               after    70.405k i/100ms
Calculating -------------------------------------
               after    690.021k (± 3.8%) i/s    (1.45 μs/i) -      3.450M in   5.007544s

Comparison:
               after:   690021.2 i/s
              before:   251477.5 i/s - 2.74x  slower

When we switch to "system lights", a hottest path will have a very little overhead for light instantiation:

Stoplight(name).run {. ... } # <- Faster lookup

@bolshakov bolshakov marked this pull request as draft May 23, 2026 15:45
@bolshakov bolshakov force-pushed the feature/lights-cache branch from 88923f9 to ccf1403 Compare May 24, 2026 07:58
@bolshakov bolshakov changed the title Cover System with tests Optimize light configuration and caching May 24, 2026
@bolshakov bolshakov marked this pull request as ready for review May 24, 2026 08:06
@bolshakov bolshakov requested a review from Lokideos May 24, 2026 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant