Skip to content

Conversation

@google-labs-jules
Copy link
Contributor

@google-labs-jules google-labs-jules bot commented Jan 11, 2026

⚡ Bolt Optimization: compareTo Zero-Allocation Parser

💡 What: Refactored compareTo to use a manual character-by-character parser instead of split, replace, and RegExp.
🎯 Why: Version comparison is a hot path. The previous implementation allocated multiple strings and arrays for every comparison, creating garbage collection pressure.
📊 Impact:

  • 13x speedup in synthetic benchmarks (3723ms -> 285ms).
  • Zero memory allocation per call (besides primitive stack variables).
    🔬 Measurement:
  • Verified with bench.ts (1M iterations over 7 version strings).
  • Verified correctness with existing test suite (bun run test).

PR created automatically by Jules for task 11172138652610001456 started by @srod


Summary by cubic

Rewrote compareTo to a zero-allocation, single-pass parser to remove regex/split overhead and cut GC pressure. Delivers ~13x speedup in benchmarks (3723ms -> 285ms for 1M calls) with the same comparison behavior.

  • Refactors
    • Replaces replace/split/RegExp with a charCodeAt loop; no heap allocations.
    • Strict parsing: supports optional v/V prefix; digits-only segments; rejects invalid chars, empty segments, or trailing dots (returns NaN).
    • Preserves segment-by-segment comparison (missing parts treated as 0); verified by tests and bench.

Written for commit 9c0b23d. Summary will update on new commits.

Replaces the regex and split-based version parser with a single-pass `charCodeAt` parser.
- Avoids array allocation from `split('.')`
- Avoids string allocation from `replace()` and `trim()`
- Avoids RegExp overhead
- Maintains strict validation parity (rejects whitespace, invalid chars)

Benchmark: ~13x speedup (3723ms -> 285ms for 1M iterations)
@google-labs-jules
Copy link
Contributor Author

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@changeset-bot
Copy link

changeset-bot bot commented Jan 11, 2026

⚠️ No Changeset found

Latest commit: 9c0b23d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Jan 11, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant