-
Notifications
You must be signed in to change notification settings - Fork 186
benchmark package and entire status optimization #420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
evisdren
wants to merge
5
commits into
main
Choose a base branch
from
benchmarking
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1dae8ae
add first benchmark for writetemporary and write committed
evisdren be1fc53
add entire status benchmark
evisdren 82c7928
process level cache for git common dir
evisdren cc204a3
add tests
evisdren b9acd16
update run instrucs and seedshadowbranch
evisdren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "io" | ||
| "testing" | ||
|
|
||
| "github.com/entireio/cli/cmd/entire/cli/benchutil" | ||
| "github.com/entireio/cli/cmd/entire/cli/paths" | ||
| "github.com/entireio/cli/cmd/entire/cli/session" | ||
| ) | ||
|
|
||
| /* To use the interactive flame graph, run: | ||
|
|
||
| mise exec -- go tool pprof -http=:8089 /tmp/status_cpu.prof &>/dev/null & echo "pprof server started on http://localhost:8089" | ||
|
|
||
| and then go to http://localhost:8089/ui/flamegraph | ||
|
|
||
| */ | ||
|
|
||
| // BenchmarkStatusCommand benchmarks the `entire status` command end-to-end. | ||
| // This is the top-level entry point for understanding status command latency. | ||
| // | ||
| // Key I/O operations measured: | ||
| // - git rev-parse --show-toplevel (RepoRoot, cached after first call) | ||
| // - git rev-parse --git-common-dir (NewStateStore, per invocation) | ||
| // - git rev-parse --abbrev-ref HEAD (resolveWorktreeBranch, per unique worktree) | ||
| // - os.ReadFile for settings.json, each session state file | ||
| // - JSON unmarshaling for settings and each session state | ||
| // | ||
| // The primary scaling dimension is active session count. | ||
| func BenchmarkStatusCommand(b *testing.B) { | ||
| b.Run("Short/NoSessions", benchStatus(0, false)) | ||
| b.Run("Short/1Session", benchStatus(1, false)) | ||
| b.Run("Short/5Sessions", benchStatus(5, false)) | ||
| b.Run("Short/10Sessions", benchStatus(10, false)) | ||
| b.Run("Short/20Sessions", benchStatus(20, false)) | ||
| b.Run("Detailed/NoSessions", benchStatus(0, true)) | ||
| b.Run("Detailed/5Sessions", benchStatus(5, true)) | ||
| } | ||
|
|
||
| func benchStatus(sessionCount int, detailed bool) func(*testing.B) { | ||
| return func(b *testing.B) { | ||
| repo := benchutil.NewBenchRepo(b, benchutil.RepoOpts{}) | ||
|
|
||
| // Create active session state files in .git/entire-sessions/ | ||
| for range sessionCount { | ||
| repo.CreateSessionState(b, benchutil.SessionOpts{}) | ||
| } | ||
|
|
||
| // runStatus uses paths.RepoRoot() which requires cwd to be in the repo. | ||
| b.Chdir(repo.Dir) | ||
| paths.ClearRepoRootCache() | ||
| session.ClearGitCommonDirCache() | ||
|
|
||
| b.ResetTimer() | ||
| for range b.N { | ||
| // Clear caches each iteration to simulate a fresh CLI invocation. | ||
| // In real usage, each `entire status` call starts cold. | ||
| paths.ClearRepoRootCache() | ||
| session.ClearGitCommonDirCache() | ||
|
|
||
| if err := runStatus(io.Discard, detailed); err != nil { | ||
| b.Fatalf("runStatus: %v", err) | ||
| } | ||
| } | ||
| } | ||
| } |
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These benchmarks reuse the same temp repo across iterations while mutating git history/metadata on each loop. That makes later iterations operate on a larger repo/branch than early iterations, which can skew benchmark results and reduce comparability. Consider moving repo/session setup inside the loop with the timer stopped (or recreate/reset the repo/branches per iteration) so each iteration measures the same steady-state work.