Skip to content

Trimmer optimization#56

Merged
bleroy merged 1 commit into
bleroy:mainfrom
kvpt:trimmer
Apr 1, 2026
Merged

Trimmer optimization#56
bleroy merged 1 commit into
bleroy:mainfrom
kvpt:trimmer

Conversation

@kvpt
Copy link
Copy Markdown

@kvpt kvpt commented Mar 31, 2026

Current trimmer implementation use Regex which is slow.
Replace it with native string manipulation.
This is about 100x faster and also this don't reallocate a string if not needed, so less allocation on average.

Before :

Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
TrimAll 1.007 us 0.0057 us 0.0054 us 0.0114 - - 192 B

After :

Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
TrimAll 65.02 ns 0.437 ns 0.388 ns 0.0101 - - 160 B

@bleroy
Copy link
Copy Markdown
Owner

bleroy commented Mar 31, 2026

Nice! I'll test that as soon as I can.

Comment thread LunrCore/Trimmer.cs
Comment thread LunrCore/Trimmer.cs
Copy link
Copy Markdown
Owner

@bleroy bleroy left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, this looks mostly good, I just have a few minor requests.

Comment thread LunrCore/Trimmer.cs
@bleroy bleroy merged commit 499f4aa into bleroy:main Apr 1, 2026
1 check passed
@bleroy
Copy link
Copy Markdown
Owner

bleroy commented Apr 1, 2026

Thanks!

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