Skip to content

Performance: Cache config#276

Open
cllns wants to merge 6 commits intomainfrom
performance/cache-config
Open

Performance: Cache config#276
cllns wants to merge 6 commits intomainfrom
performance/cache-config

Conversation

@cllns
Copy link
Copy Markdown
Member

@cllns cllns commented May 5, 2026

~28% fewer allocations (138 -> 99) per render
~18% fewer bytes used (8,739 -> 7,160) per render

+36.8% iteration speed (30,891 ips -> 42,266 ips, 32.4μs -> 23.7μs per render)

(Updated these numbers. The early improvements weren't as high but I closed some apps 😇 and these seem to be consistent)

Using benchmarks/view_benchmark.rb on Ruby 4 (on an M1 Pro).

I originally had this with a class-level self.cached_config which isn't necessary so I removed it. This means each instantiation of a view has to compute cached_config for itself, adding some overhead. Since we've built this library based on the assumption that a single View will be re-used (rather than created new each time it's used), I think that's fine. Open to other perspectives though!

Another option is using reader: true for all of the settings. I experimented with this too, but it's not as clean, because the settings are set on the View class rather than the config, so view_class has to be passed around everywhere, which hides the intent of sending just config settings around. It's got basically the same performance as this approach though.

cllns added 3 commits May 4, 2026 23:20
~22% fewer allocations (161 -> 125)
~14% fewer bytes used (9,936 -> 8,496)

+18.7% iteration speed (23,114 ips -> 27,438 ips, 43.3μs -> 36.5μs per render)

Using benchmarks/view_benchmark.rb on Ruby 4 (on an M1 Pro)
@timriley
Copy link
Copy Markdown
Member

timriley commented May 5, 2026

Thanks for looking into this stuff, @cllns! My question is whether we might actually be able to solve this at a Dry Configurable level, rather than create a workaround for it here? We use Dry Configurable in many other places, so a solve there once would benefit us more.

@cllns
Copy link
Copy Markdown
Member Author

cllns commented May 6, 2026

@timriley I was already working on it :) Just had to figure out the right API. See: dry-rb/dry-configurable#167 and updated changes here.

I made a few tiny refactors to move things into private visibility. There's more I want to do, but I'll do that as a follow-on, so this PR doesn't get too complicated.

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.

2 participants