-
Notifications
You must be signed in to change notification settings - Fork 561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use string concatenation to increase performance #336
Conversation
@JedWatson @dcousens Since this refactors a pretty large swath of code from the core part of the library, I'd like to have a more formal review on this one. Let me know if you're available. |
b4a328e
to
a246c8c
Compare
Happy with this conceptually, but, probably need to verify this result across different browsers, the |
Similar to #292 |
Sure, I can run some browser benchmarks and get back to this 👍 |
a246c8c
to
e9025a2
Compare
@dcousens updated the PR description with benchmarks in all the latest versions of major browsers. And added some code to easily format the results as markdown. |
Numbers LGTM, limited regressions and the major usecases |
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [classnames](https://github.com/JedWatson/classnames) | dependencies | minor | [`2.3.1` -> `2.5.1`](https://renovatebot.com/diffs/npm/classnames/2.3.1/2.5.1) | --- ### Release Notes <details> <summary>JedWatson/classnames (classnames)</summary> ### [`v2.5.1`](https://github.com/JedWatson/classnames/blob/HEAD/HISTORY.md#v251--2023-12-29) [Compare Source](JedWatson/classnames@v2.5.0...v2.5.1) - Remove `workspaces` field from package ([#​350](JedWatson/classnames#350)) ### [`v2.5.0`](https://github.com/JedWatson/classnames/blob/HEAD/HISTORY.md#v250--2023-12-27) [Compare Source](JedWatson/classnames@v2.4.0...v2.5.0) - Restore ability to pass a TypeScript `interface` ([#​341](JedWatson/classnames#341)) - Add `exports` field to package ([#​342](JedWatson/classnames#342)) ### [`v2.4.0`](https://github.com/JedWatson/classnames/blob/HEAD/HISTORY.md#v240--2023-12-26) [Compare Source](JedWatson/classnames@v2.3.3...v2.4.0) - Use string concatenation to increase performance thanks [Jon Koops](https://github.com/jonkoops) ([#​336](JedWatson/classnames#336)) ### [`v2.3.3`](https://github.com/JedWatson/classnames/blob/HEAD/HISTORY.md#v233--2023-12-21) [Compare Source](JedWatson/classnames@v2.3.2...v2.3.3) - Fix default export, thanks [Remco Haszing](https://github.com/remcohaszing) ([#​301](JedWatson/classnames#301)) - Fix types for read-only arrays, thanks [Ben Thompson](https://github.com/BenGearset) ([#​307](JedWatson/classnames#307)) - Replace README examples with functional-style components, thanks [JoeDGit](https://github.com/JoeDGit) ([#​303](JedWatson/classnames#303)) ### [`v2.3.2`](https://github.com/JedWatson/classnames/blob/HEAD/HISTORY.md#v232--2022-09-13) [Compare Source](JedWatson/classnames@v2.3.1...v2.3.2) - Fix TypeScript types when using require, thanks [Mark Dalgleish](https://github.com/markdalgleish) ([#​276](JedWatson/classnames#276)) - Fix toString as `[Object object]` in a vm, thanks [Remco Haszing](https://github.com/remcohaszing) ([#​281](JedWatson/classnames#281)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4xNDIuNSIsInVwZGF0ZWRJblZlciI6IjM4LjE0Mi41IiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbXX0=--> Reviewed-on: https://gitea.bruyant.xyz/alexandre/PaletteSwitcher/pulls/48 Co-authored-by: Renovate <[email protected]> Co-committed-by: Renovate <[email protected]>
Replaces the logic that holds class names in an array and joins them together in the end with direct string concatenation, this results in ~30% performance increase across the board. The following benchmarks were ran on my 2021 MacBook Pro 14-inch with an M1 Pro chip running macOS Sonoma (14.2.1):
Node.js (v21.5.0)
Benchmarking 'strings'.
Benchmarking 'object'.
Benchmarking 'strings, object'.
Benchmarking 'mix'.
Benchmarking 'arrays'.
Firefox (v121.0)
Benchmarking 'strings'.
Benchmarking 'object'.
Benchmarking 'strings, object'.
Benchmarking 'mix'.
Benchmarking 'arrays'.
Chrome (v20.0.6099.129)
Benchmarking 'strings'.
Benchmarking 'object'.
Benchmarking 'strings, object'.
Benchmarking 'mix'.
Benchmarking 'arrays'.
Safari (v17.2.1)
Benchmarking 'strings'.
Benchmarking 'object'.
Benchmarking 'strings, object'.
Benchmarking 'mix'.
Benchmarking 'arrays'.