This repository was archived by the owner on Oct 31, 2024. It is now read-only.
Optimize StringBuilder based loops#52
Merged
iconara merged 1 commit intoburtcorp:masterfrom Jun 7, 2019
gatling:stringbuilder
Merged
Optimize StringBuilder based loops#52iconara merged 1 commit intoburtcorp:masterfrom gatling:stringbuilder
iconara merged 1 commit intoburtcorp:masterfrom
gatling:stringbuilder
Conversation
Motivation: Nodes' internalToString and ParseExceptions uses StringBuilder based loops. Even tough those shouldn't be on the hot path if Expressions are cached, they still can be optimized. Modifications: Stop using Iterators with nested hasNext tests. Use simple for loops that have a chance of being JIT'ed with escape analysis. Don't test last element in loop (cf above). Update StringBuilder's length after loop if it wasn't empty. Don't use StringBuilder#delete that causes a copy of the underlying char array. Update StringBuilder's length instead as we always want to remove the tail. Result: Less allocations
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Motivation:
Nodes' internalToString and ParseExceptions uses StringBuilder based loops. Even tough those shouldn't be on the hot path if Expressions are cached, they still can be optimized.
Modifications:
Stop using Iterators with nested hasNext tests. Use simple for loops that have a chance of being JIT'ed with escape analysis.
Don't test last element in loop (cf above). Update StringBuilder's length after loop if it wasn't empty.
Don't use StringBuilder#delete that causes a copy of the underlying char array. Update StringBuilder's length instead as we always want to remove the tail.
Result:
Less allocations