Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always cache config values #157

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

HashNotAdam
Copy link

When retrieving a value from Dry::Configurable::Config#[], the value is only cached to the _values array if it is considered "cloneable". Unfortunately, checking for cloneability is a costly exercise (at least when called at the frequency of Dry::View).

The code states that this occurs as a means of helping understand when a setting has been mutated; however, I would like to suggest that the increase in performance that can be achieved in Dry::View rendering is more valuable. Saying this, I suggest modifying Dry::View rather than Dry::Configurable::Config because I doubt most uses have the same performance requirements.

In my benchmarks, I'm using a highly contrived template that loads 100 nested templates that do nothing more than print out their name as well a couple of random numbers to ensure values aren't being cached so, while it is designed somewhat to replicate a site with many components, it's far from true to life. Saying this, my tests have found this has given me a roughly 70% performance increase:

Calculating -------------------------------------
              Before    100.263  (±12.0%) i/s -      1.008k in  10.076792s
               After    169.272  (± 7.1%) i/s -      1.696k in  10.076434s

It's tricky to solve this elegantly so I'm very open to discussing alternative approaches.

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.

None yet

1 participant