Skip to content

Conversation

@jakebailey
Copy link
Member

The Go compiler isn't smart enough to elide the []byte conversion from any of these. Thankfully. the xxhash library has a string variant!

Reduces the memory allocated in fourslash by 50% and makes them about 30% faster.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes hash computation by using xxh3.HashString128() directly on strings instead of converting strings to byte slices first with xxh3.Hash128([]byte(content)). This optimization eliminates unnecessary allocations, resulting in 50% reduction in memory usage and 30% faster performance in fourslash tests.

Key Changes:

  • Replaced 6 instances of xxh3.Hash128([]byte(content)) with xxh3.HashString128(content) across 3 files
  • No behavioral changes, as both functions return the same xxh3.Uint128 type

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
internal/project/snapshotfs.go Updated hash computation when reloading disk file content
internal/project/overlayfs.go Updated hash computation in 4 locations: disk file creation, overlay creation, disk text comparison, and overlay content changes
internal/execute/incremental/snapshot.go Updated hash computation in the ComputeHash function

The changes look excellent! This is a clean performance optimization that:

  • ✅ Consistently replaces all instances of the pattern
  • ✅ Maintains semantic equivalence (both functions return xxh3.Uint128)
  • ✅ Eliminates unnecessary string-to-byte-slice conversions
  • ✅ Achieves significant performance improvements as stated in the PR description

No issues were found during the review. The changes are straightforward, consistent, and correct.

@jakebailey jakebailey enabled auto-merge December 12, 2025 18:56
@jakebailey jakebailey added this pull request to the merge queue Dec 12, 2025
Merged via the queue into main with commit 20cf78d Dec 12, 2025
28 checks passed
@jakebailey jakebailey deleted the jabaile/hash-string branch December 12, 2025 19:27
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.

4 participants