sallar / sallar/stringz

Ideas for perf improvements on long strings

Open
#26 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
238
Forks
10
PR merge metrics
No merged PRs in 30d

Description

Hello @sallar,

Thanks for this great library! My application can potentially be running ‘substr’ on many long strings at the same time, so perf is very important. I noticed that ‘substr’ (etc) uses ‘match’ which runs the RegExp on the entire string. This can be quite expensive for long string especially if ‘substr’s ‘length’ is much shorter than the entire string.

So far I only have one idea: to use ‘exec’ with a while loop in the case that ‘length’ is much shorter than the entire ‘string’*. Do you have any other ideas for perf improvements? I would be happy to implement them and send you PRs.

*See benchmarks: https://jsperf.com/regex-exec-vs-match-for-long-strings/1

Thanks

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the implementations of substr and related methods that use match, then review the linked jsPerf benchmark and compare it with an exec-based approach on long strings. Done requires an agreed optimization scope and benchmark evidence showing the relevant operations improve without changing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
performance
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.