Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
mgol merged 1 commit intojquery:mainfromvlsi:faster_trim
Jul 20, 2022

Conversation

vlsi
Copy link
Contributor

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: ifString.prototype.trim() is good enough, then the implementation would use it.

@linux-foundation-easycla
Copy link

linux-foundation-easyclabot commentedApr 25, 2022
edited
Loading

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: vlsi / name: Vladimir Sitnikov (c962c28)

@vlsivlsiforce-pushed thefaster_trim branch 2 times, most recently from001ac34 to185d4b5CompareApril 25, 2022 12:56
@mgol
Copy link
Member

mgol commentedJun 27, 2022
edited
Loading

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 nativetrim. Please take that into account.

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)

@mgolmgol closed thisJun 27, 2022
@vlsi
Copy link
ContributorAuthor

vlsi commentedJun 27, 2022
edited
Loading

@mgol , the exact.trim method has beenremoved from the base jQuery, so I believe there's no way the contribution could be accepted to jQuery:jquery/jquery@0b676ae


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 trim. Please take that into account.

My edge case is that my JIRA instance takes20 seconds to display an issue (it spends most of that time withinjquery.trim).

The implementation is really straightforward, and it doesn't make jquery-migrate significantly bigger.

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

I am OK to fix the issues if you merge the PR, however,

  1. The PR has been "in review" for 2 months
  2. You seem to want to close the PR even though it impacts the end-users. Do you really suggest that I should spend MY time on fixing the CI issues with the only outcome of you closing the PR as "won't merge"?

@mgol
Copy link
Member

mgol commentedJun 27, 2022
edited
Loading

It was removed from themain branch of jQuery; this is the branch where we're merging changes that will land in jQuery 4.0.0 when it's ready. The latest stable line is3.x and it's developed on the3.x-stable branch; the PR would have to be submitted against this branch.

I am OK to fix the issues if you merge the PR, however,

1. The PR has been "in review" for 2 months

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.

2. You seem to want to close the PR even though it impacts the end-users. Do you really suggest that I should spend MY time on fixing the CI issues with the only outcome of you closing the PR as "won't merge"?

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.

@mgol
Copy link
Member

@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.

@mgolmgol reopened thisJul 20, 2022
Copy link
Member

@mgolmgol left a 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.
Copy link
Member

@mgolmgol left a comment

Choose a reason for hiding this comment

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

Thank you!

@mgolmgol added this to the3.4.1 milestoneJul 20, 2022
@mgolmgol changed the titlePerformance: improve .trim performance for large strings contains lots of whitespacesDeprecated: Improve $.trim performance for strings with lots of whitespaceJul 20, 2022
@mgolmgol merged commit69a2441 intojquery:mainJul 20, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@mgolmgolmgol approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
3.4.1
Development

Successfully merging this pull request may close these issues.

2 participants
@vlsi@mgol

[8]ページ先頭

©2009-2025 Movatter.jp