perf(routing): eliminate unnecessary allocations per request#1585
Open
tkan145 wants to merge 6 commits into
Open
perf(routing): eliminate unnecessary allocations per request#1585tkan145 wants to merge 6 commits into
tkan145 wants to merge 6 commits into
Conversation
Previously, TemplateString.new is called per-request inside the closure. The liquid template is static so we only need to parse it once at init time.
Previously, a new Operation object was allocated for each request. The value on the right is static, so we can allocate that value beforehand in the constructor, while the value on the left is always evaluated as a regular string, so we just pass it in as is and avoid allocating another TemplateString.
ccb1c9e to
ca48ae1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Performance refactor to avoid unnecessary allocation per request.
Perf scripts
Details
Perf results
Warming up -------------------------------------- Operation.new per-request (==) 920530 i/100ms pre-resolved compare (==) 3716779 i/100ms Operation.new per-request (matches) 120903 i/100ms pre-resolved compare (matches) 138079 i/100ms liquid: parse+render (per-request) 16728 i/100ms liquid: cached render 69192 i/100ms plain: render (baseline) 216056 i/100ms per-request closure alloc 195534 i/100ms module-level function ref 219908 i/100ms Calculating ------------------------------------- Operation.new per-request (==) 11268321.1 (±0.6%) i/s - 57072860 in 5.065098s pre-resolved compare (==) 83650585.7 (±1.0%) i/s - 419996027 in 5.021378s Operation.new per-request (matches) 1174708.5 (±2.6%) i/s - 5924247 in 5.046572s pre-resolved compare (matches) 1223650.6 (±13.3%) i/s - 6075476 in 5.051734s liquid: parse+render (per-request) 142548.8 (±4.3%) i/s - 719304 in 5.056303s liquid: cached render 588118.2 (±6.8%) i/s - 2975256 in 5.084045s plain: render (baseline) 77910469.3 (±3.0%) i/s - 389332912 in 5.001722s per-request closure alloc 18210146.5 (±3.6%) i/s - 91118844 in 5.010522s module-level function ref 87281446.6 (±1.8%) i/s - 436297472 in 5.000413sConclusion