Skip to content

promote countGraphemes() to a fast path - #140

Merged
cometkim merged 6 commits into
mainfrom
fast-counter-path
Jul 22, 2026
Merged

cometkim merged 6 commits into
mainfrom
fast-counter-path

Conversation

@cometkim

Copy link
Copy Markdown
Owner

No description provided.

@changeset-bot

changeset-bot Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3d31a70

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
unicode-segmenter Patch

Not sure what this means? Click here to learn what changesets are.

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

@pkg-pr-new

pkg-pr-new Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/unicode-segmenter@140

commit: 3d31a70

@codspeed

codspeed Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by ×2.3

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 6 improved benchmarks
✅ 12 untouched benchmarks
⏩ 12 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ countGraphemes - Code snippet (combined) 158 µs 41.8 µs ×3.8
⚡ countGraphemes - Tweet text (combined) 78.3 µs 27.3 µs ×2.9
⚡ countGraphemes - Lorem ipsum (ascii) 58.3 µs 21.8 µs ×2.7
⚡ countGraphemes - Hindi 55 µs 24.8 µs ×2.2
⚡ countGraphemes - Emojis 31.5 µs 18.3 µs +71.51%
⚡ countGraphemes - Demonic characters 39.2 µs 32.3 µs +21.24%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fast-counter-path (3d31a70) with main (2ac327c)2

Open in CodSpeed

Footnotes

  1. 12 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (b1a0807) during the generation of this report, so 2ac327c was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@cometkim

cometkim commented Jul 22, 2026 •

Copy link
Copy Markdown
Owner Author

Since splitGraphemes() is the same generator implementation anyway, it has the same overhead. There is no value in adding duplicate code here.

If a new function based on an array buffer were added, it could perform about 2x as fast on small text, so it is worth considering providing this as an additional API. e.g. splitGraphemesToArray()

Which is actually the most used one I guess.

@cometkim cometkim changed the title make countGraphemes/splitGraphemes fast paths promote countGraphemes() as fast path Jul 22, 2026
@cometkim cometkim changed the title promote countGraphemes() as fast path promote countGraphemes() to a fast path Jul 22, 2026
@cometkim
cometkim merged commit 5fcaa4f into main Jul 22, 2026
4 checks passed
@cometkim
cometkim deleted the fast-counter-path branch July 22, 2026 08:53
@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2ac327c) to head (3d31a70).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #140   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         9           
  Lines          940       973   +33     
=========================================
+ Hits           940       973   +33     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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