Skip to content

⚡ Bolt: Replace indexOf with inline checks for performance#28

Open
ericbfriday wants to merge 1 commit into
masterfrom
bolt-optimize-indexof-17375214573282474445
Open

⚡ Bolt: Replace indexOf with inline checks for performance#28
ericbfriday wants to merge 1 commit into
masterfrom
bolt-optimize-indexof-17375214573282474445

Conversation

@ericbfriday
Copy link
Copy Markdown
Owner

💡 What: Replaced single-character String.prototype.indexOf calls in luaparse.js with direct inline equality (===) checks.
🎯 Why: In critical paths like lexing/token generation, String.prototype.indexOf introduces function call overhead that impacts parse speed. V8 handles simple inline branching and strict equality comparisons much faster.
📊 Impact: Increases parsing throughput. Benchmarks run locally showed an improvement from ~299 ops/sec to ~309 ops/sec.
🔬 Measurement: Verify functionality with npm run test (all 2447 tests pass). Run npm run bench:luast to observe parsing speed improvements.


PR created automatically by Jules for task 17375214573282474445 started by @ericbfriday

Copilot AI review requested due to automatic review settings May 23, 2026 23:59
@google-labs-jules
Copy link
Copy Markdown

👋 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.

Copy link
Copy Markdown

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 luaparse.js hot-path character checks by replacing single-character String.prototype.indexOf membership tests with direct inline === comparisons, aiming to improve lexer/tokenization throughput.

Changes:

  • Replaced several single-character '.indexOf(...) >= 0' checks with inline === comparisons in numeric literal parsing and other parser helpers.
  • Added a short internal note under .jules/ documenting the optimization rationale and guidance.

Reviewed changes

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

File Description
luaparse.js Replaces single-character indexOf checks with direct equality comparisons in lexer/parser hot paths.
.jules/bolt.md Adds a brief markdown note documenting the performance rationale and preferred pattern.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread luaparse.js
Comment on lines +1072 to +1073
var ch4 = input.charAt(index);
if (ch4 === 'l' || ch4 === 'L') {
Comment thread luaparse.js
Comment on lines +1137 to 1138
if (chSign1 === '+' || chSign1 === '-')
binarySign = ('+' === input.charAt(index++)) ? 1 : -1;
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