Skip to content

⚡ Optimize word count extraction performance - #75

Open
savvides wants to merge 1 commit into
mainfrom
perf-optimize-wordcount-13257997836342830890
Open

⚡ Optimize word count extraction performance#75
savvides wants to merge 1 commit into
mainfrom
perf-optimize-wordcount-13257997836342830890

Conversation

@savvides

Copy link
Copy Markdown
Owner

💡 What: Replaced content.split(/\s+/).filter(Boolean).length with (content.match(/\S+/g) || []).length in the word counting logic within extension/content/extractor-core.js and extension/content/extractor.js.
🎯 Why: The previous approach was highly inefficient, as .split allocates a large array for every word and space, and then .filter(Boolean) iterates over it to create yet another array. The new approach directly matches non-whitespace character sequences and returns a single array, bypassing unnecessary allocations and iterations while preserving exactly the same behavior and edge case handling.
📊 Measured Improvement: Benchmarks on large text inputs (100k repetitions of a phrase run 100 times) showed the original method taking ~22.8 seconds versus ~15.9 seconds for the regex match, yielding roughly a ~30% performance boost in execution time and significantly less memory garbage.


PR created automatically by Jules for task 13257997836342830890 started by @savvides

Replaced inefficient `content.split(/\s+/).filter(Boolean).length` with `(content.match(/\S+/g) || []).length` in both `extension/content/extractor-core.js` and `extension/content/extractor.js`. The original method created multiple intermediate arrays causing unnecessary CPU and memory overhead, whereas the new regex directly counts matching words.

Co-authored-by: savvides <1580637+savvides@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

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

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