Different performance optimizations #466
Merged
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.
The primary enhancement in this PR pertains to StackedSet, where we've replaced the underlying data structure, Stack, with Deque. This change significantly improves performance by eliminating the need for synchronization.
Additionally, we've revamped the construction of the collapsed stack. Rather than using an isDirty flag and rebuilding the entire collapsed set each time there's a modification, we've opted for an incremental approach. Now, the collapsed set is built each time the stacked set is altered, thereby avoiding the need to recreate the collapsed stack entirely.
We've also optimized the 'lineCount' method in some modules. Instead of using a stream and calling the 'mapToInt' method, which carries a significant overhead, we've chosen to use a simple 'for' loop. This change enhances performance by reducing unnecessary complexity.
We can find below the CPU profiling before and after this PR
Before this PR

After this PR
