- Notifications
You must be signed in to change notification settings - Fork476
Deprecated: Improve $.trim performance for strings with lots of whitespace#461
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
linux-foundation-easyclabot commentedApr 25, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
|
001ac34
to185d4b5
Comparemgol commentedJun 27, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thanks for the PR. With Migrate, we're more concerned about backwards compatibility than performance. This is why implementation of various methods is based on how they were implemented in jQuery before deprecation/removal. The implementation here shouldn't be changed before the upstream version in jQuery is updated; you can find it athttps://github.com/jquery/jquery/blob/3.x-stable/src/deprecated.js. One advantage of making a change in jQuery first is that it has a more comprehensive test suite so any mistakes in the implementation would be detected better. That said, since the util is deprecated, we'd rather not increase the library size to address an edge case that people shouldn't rely on anyway as we recommend migrating to native Since any action should first be taken in jQuery upstream, I'm going to close the PR. If a change to jQuery gets accepted, we can then backport the change here. (note: when submitting a PR, please address any checks errors GitHub throws at you; for example, this PR had a lot of code style errors) |
vlsi commentedJun 27, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@mgol , the exact
My edge case is that my JIRA instance takes20 seconds to display an issue (it spends most of that time within The implementation is really straightforward, and it doesn't make jquery-migrate significantly bigger.
I am OK to fix the issues if you merge the PR, however,
|
mgol commentedJun 27, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
It was removed from the
This project is volunteer-driven, I don't have active support contract with anyone. And it so happened that I was on vacation recently and before the vacation I was busy at work with hardly any time for open source work. I'm reviewing PRs when I have time. Usually it doesn't take two months but from time to time I have less time for OSS; you can't expect me to always reply within a given time frame.
I explained why changes need to land in jQuery upstream first, at least as long as the code is still maintained there which is the case here. My time is limited. I'd be happy to review your PR to jQuery. When you submit a PR to an OSS project, you can't always expect it will get merged; sometimes it doesn't align with the project priorities. In case of jQuery, if you want to avoid spending time on CI issues only to see your PR rejected, it's a good idea to open an issue first, present a concrete use case (like the JIRA example you mentioned here - without a concrete case like that, we can't know if the issue is worth fixing) and wait for the team to approve the approach; then your PR may still get requests for changes but will generally be merged when those are addressed. For the record, I think this would be a good change to land, although we'd like to compress the code a bit. It's also likely that we'd prefer to use the regex approach in all browsers to make the code smaller; that should still resolve your performance concerns as much as I understand. |
@vlsi Sincejquery/jquery#5068 landed, I'm going to reopen this PR. We can merge it if you update the implementation here to match the one that landed in the jQuery PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Marking as "Request changes" until the implementation is updated to match the jQuery one fromjquery/jquery#5068.
…s of whitespacesThe old implementation took O(N^2) time to trim the string when multiple adjacent spaceswere present.For instance, consider the string "A B" (10 spaces between A and B).Then old regexp /[\s]+$/ would take 10 steps until it realizesthe regexp does not match at position 1.Then it would try to match the regexp at position 2, and it would take 9 steps.Then 8 steps for position 3, ... so it would take 10*10/2 steps untilit figures out the regexp does not match.Seejquery/jquery#5068The new approach is to require "non-whitespace" char before the whitespace run,so it spends just one step for each space in the string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thank you!
The old implementation took O(N^2) time to trim the string when multiple adjacent spaces
were present.
For instance, consider the string "A B" (10 spaces between A and B).
Then old regexp /[\s]+$/ would take 10 steps until it realizes the regexp does not match at position 1.
Then it would try to match the regexp at position 2, and it would take 9 steps.
Then 8 steps for position 3, ... so it would take 10*10/2 steps until it figures out the regexp does not match.
The new approach is to require "non-whitespace" char before the whitespace run, so it spends just one step for each space in the string.
Note: if
String.prototype.trim()
is good enough, then the implementation would use it.