sindresorhus / camelcase

Convert a dash/dot/underscore/space separated string to camelCase: foo-bar → fooBar
MIT License
682 stars 95 forks source link

Improve performance by reusing precompiled regular expressions #85

Closed nazar-pc closed 2 years ago

nazar-pc commented 3 years ago

Found this in CPU-bound application, should help significantly when called often.

I am not familiar with the library, would be nice if someone renames variables to something more meaningful.

sindresorhus commented 3 years ago

Found this in CPU-bound application, should help significantly when called often.

Did you actually measure the performance improvement? V8 is often able to inline this anyway, so from experience, whether they are inline or top-level matter very little.

sindresorhus commented 3 years ago

You'll also need to come up with some better names for the variables for this to be mergable.

nazar-pc commented 3 years ago

Did you actually measure the performance improvement? V8 is often able to inline this anyway, so from experience, whether they are inline or top-level matter very little.

I do not have a reproducible benchmark. This library is used as dependency of the other library and I found during profiling that a non-negligible amount of time was spent in this library. After changes from this PR I have not seen library doing significant contributions. One would expect something like this to be optimized, but I don't think V8 is doing that right now.

You'll also need to come up with some better names for the variables for this to be mergable.

I am not familiar with the library at all, so I have no idea what those things do and what they should be called unfortunately.

sindresorhus commented 2 years ago

I am not familiar with the library at all, so I have no idea what those things do and what they should be called unfortunately.

You could infer it by reading the regex and looking at the context.