Skip to content

feat: Optimize lazy context tracking and descendant traversal performance#2

Merged
daveshanley merged 1 commit intopb33f:mainfrom
andreyyudin:feature/lazy-context-tracking
Feb 14, 2026
Merged

feat: Optimize lazy context tracking and descendant traversal performance#2
daveshanley merged 1 commit intopb33f:mainfrom
andreyyudin:feature/lazy-context-tracking

Conversation

@andreyyudin
Copy link

@andreyyudin andreyyudin commented Feb 10, 2026

Summary

  • Added config.WithLazyContextTracking() for on-demand context-variable tracking.
  • Preserved backward compatibility by keeping eager tracking as the default.
  • Optimized descendant traversal using iterative descendApply to reduce allocations.
  • Added reproducible benchmarks for descendant traversal and lazy tracking.

Benchmark Prerequisites

Install benchstat once:

go install golang.org/x/perf/cmd/benchstat@latest

If benchstat is not on your PATH, invoke it as:

$(go env GOPATH)/bin/benchstat ...

How To Benchmark (Reproducible)

1) Descendant traversal (descendApply) before/after (n=15)

# feature branch
git checkout feature/lazy-context-tracking
go test ./pkg/jsonpath -bench BenchmarkDescendantQuery -benchmem -run '^$' -benchtime=5s -count=15 > /tmp/feat_desc.txt

# main baseline (reuse benchmark file from feature branch)
git checkout main
git checkout feature/lazy-context-tracking -- pkg/jsonpath/yaml_query_test.go
go test ./pkg/jsonpath -bench BenchmarkDescendantQuery -benchmem -run '^$' -benchtime=5s -count=15 > /tmp/main_desc.txt
git restore --source=HEAD --staged --worktree pkg/jsonpath/yaml_query_test.go

# compare
$(go env GOPATH)/bin/benchstat /tmp/main_desc.txt /tmp/feat_desc.txt

2) Lazy tracking on/off (n=15)

git checkout feature/lazy-context-tracking

LAZY_TRACKING_MODE=eager go test ./pkg/jsonpath \
  -bench BenchmarkLazyContextTrackingStress -benchmem -run '^$' \
  -benchtime=1x -count=15 -tags 'lazytracking stress' > /tmp/lazy_eager.txt

LAZY_TRACKING_MODE=lazy go test ./pkg/jsonpath \
  -bench BenchmarkLazyContextTrackingStress -benchmem -run '^$' \
  -benchtime=1x -count=15 -tags 'lazytracking stress' > /tmp/lazy_lazy.txt

$(go env GOPATH)/bin/benchstat /tmp/lazy_eager.txt /tmp/lazy_lazy.txt

Performance

Descendant traversal (BenchmarkDescendantQuery, n=15)

  • time: -20.69% (8.723ms -> 6.918ms, p=0.000)
  • bytes: -38.55% (6.128MiB -> 3.766MiB, p=0.000)
  • allocs: -49.90% (50.38k -> 25.24k, p=0.000)

Lazy tracking stress (BenchmarkLazyContextTrackingStress, n=15)

  • time: -75.18% (433.2ms -> 107.5ms, p=0.000)
  • bytes: -74.39% (158.62MiB -> 40.63MiB, p=0.000)
  • allocs: -20.30% (1.658M -> 1.321M, p=0.000)

@daveshanley daveshanley changed the title Optimize lazy context tracking and descendant traversal performance feat: Optimize lazy context tracking and descendant traversal performance Feb 14, 2026
@daveshanley
Copy link
Member

dude, this looks awesome. reviewing now.

@codecov
Copy link

codecov bot commented Feb 14, 2026

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Copy link
Member

@daveshanley daveshanley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love this! love it.

@daveshanley daveshanley merged commit 84ca93c into pb33f:main Feb 14, 2026
9 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants