Tokenizer::scan performance improvements#6
Open
sam-osborne wants to merge 2 commits intomardix:masterfrom
Open
Tokenizer::scan performance improvements#6sam-osborne wants to merge 2 commits intomardix:masterfrom
sam-osborne wants to merge 2 commits intomardix:masterfrom
Conversation
prasadvenkat
approved these changes
Jul 18, 2019
bobthecow
added a commit
to bobthecow/mustache.php
that referenced
this pull request
Jul 21, 2019
- Checking the first character of the opening and closing tags is >90% faster than baseline for my test case. - Inlining the `tagChange` method is 18% faster than baseline. - Together they yield a 98.2% wall clock time improvement! Hat tip to @sam-osborne for the first one :) mardix/Handlebars#6
|
I made the second change in mustache.php a while back and it made a huge difference: bobthecow/mustache.php@6215e6b From my testing, it looks like the "tag change" logic does best when completely inlined, and it's not any harder to follow, so that's what I went with: bobthecow/mustache.php@72d0752 |
LeSuisse
pushed a commit
to Enalean/mustache.php
that referenced
this pull request
Dec 19, 2019
- Checking the first character of the opening and closing tags is >90% faster than baseline for my test case. - Inlining the `tagChange` method is 18% faster than baseline. - Together they yield a 98.2% wall clock time improvement! Hat tip to @sam-osborne for the first one :) mardix/Handlebars#6
LeSuisse
pushed a commit
to Enalean/mustache.php
that referenced
this pull request
Dec 19, 2019
- Checking the first character of the opening and closing tags is >90% faster than baseline for my test case. - Inlining the `tagChange` method is 18% faster than baseline. - Together they yield a 98.2% wall clock time improvement! Hat tip to @sam-osborne for the first one :) mardix/Handlebars#6
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.
This PR provides a 77.6% reduction in wall time of the Tokenizer::scan method and outlines each of the changes. The profile below shows the overall difference before and after the changes to the Tokenizer::scan method. Profilers were generated based on an execution count of 10,000 and a Handlebars string of 5KB.
1: The majority of the wall time was spent in trying to detect a tag change. The internals of this method use an index to get the get a pair of characters out of the entire message to determine whether it is an opening or closing tag. Evaluating a large message this way was the main culprit of the runtime bottleneck. To avoid checking characters that we not an opening or closing tag, the first change was putting a check for an opening or closing character before executing the tagChange method. This change cut down a majority of the wall time from 144 seconds to 35 seconds given a 10,000 execution count cycle:
2: The second change was made to limit computing the length of the opening and closing tag length which avoids unnecessarily recalculating every time the tag change method was executed. This optimization brought the wall time down 1.3 seconds given a 10,000 execution count cycle.
3: The third change was to replace string lookups by index with references. The first update was to create a reference to the character in evaluation iteration and replace the text lookup by index with the reference. The second update was to create a reference for the first character in the opening and closing tag to avoid a lookup by index in the references created in the first optimization. This optimization brought the wall time down 1.4 seconds given a 10,000 execution count cycle.
Handlebars message utilized:
Happy to contribute some performance tests as well if necessary.