Optimize lazy context tracking and descendant traversal performance #2
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.
Summary
config.WithLazyContextTracking()for on-demand context-variable tracking.descendApplyto reduce allocations.Benchmark Prerequisites
Install
benchstatonce:If
benchstatis not on yourPATH, invoke it as:$(go env GOPATH)/bin/benchstat ...How To Benchmark (Reproducible)
1) Descendant traversal (
descendApply) before/after (n=15)2) Lazy tracking on/off (
n=15)Performance
Descendant traversal (
BenchmarkDescendantQuery,n=15)-20.69%(8.723ms->6.918ms, p=0.000)-38.55%(6.128MiB->3.766MiB, p=0.000)-49.90%(50.38k->25.24k, p=0.000)Lazy tracking stress (
BenchmarkLazyContextTrackingStress,n=15)-75.18%(433.2ms->107.5ms, p=0.000)-74.39%(158.62MiB->40.63MiB, p=0.000)-20.30%(1.658M->1.321M, p=0.000)