-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
It takes more than 20 seconds to paste not-so-large HTML document. #41826
Comments
@aristath wonder if you have any insights here based on some of the performance work you've done! |
I just replicated this on the Make Network (Make Core specifically). I'll try to flag this up in #core-editor to see if anyone can take a look. |
The problem is in this line/function( Also it's a great time to write a test for this. In the snippet provided in the PR do we need to also remove the
IMO if we don't find a workaround quickly enough, it would be good to revert that PR, as this affects paste in every OS and is taking a really long time.. |
Nice sleuthing! 🌟
This surprised me, so I looked at the function, thinking that const startReg = /.*<!--StartFragment-->/s;
const endReg = /<!--EndFragment-->.*/s;
return html.replace( startReg, '' ).replace( endReg, '' ); What stands out here are the Since the goal of the function is to remove the marks as well as any preceding/following whitespace, I would rewrite it as: const startStr = '<!--StartFragment-->';
const startIdx = html.indexOf( startStr );
if ( startIdx > -1 ) html = html.substring( startIdx + startStr.length );
// Possible optimisation: only run this second block if there was a match for `startStr`.
const endStr = '<!--EndFragment-->';
const endIdx = html.indexOf( endStr );
if ( endIdx > -1 ) html = html.substring( 0, endIdx ); |
Agreed on reverting if there is no quick fix. Also, the suggested test looks like it's just for pasting on Windows, but we should have performance tests for pasting larger chunks of content in general given this regression slipped through. |
I think this is a good candidate for 6.0.1. cc @adamziel |
Fixes #41826. removeWindowsFragments was running two String#replace with regular expressions made computationally expensive due to the use of `.*` and the `s / dotAll` flag, resulting in severe performance degradations when handling larger strings of HTML. The solution is to manually trim the strings via a combination of String#indexOf and String#substring.
…1907) * Pasting: Fix performance regression due to removeWindowsFragments Fixes #41826. removeWindowsFragments was running two String#replace with regular expressions made computationally expensive due to the use of `.*` and the `s / dotAll` flag, resulting in severe performance degradations when handling larger strings of HTML. The solution is to manually trim the strings via a combination of String#indexOf and String#substring. * removeWindowsFragments: bail early if no StartFragment found
…1907) * Pasting: Fix performance regression due to removeWindowsFragments Fixes #41826. removeWindowsFragments was running two String#replace with regular expressions made computationally expensive due to the use of `.*` and the `s / dotAll` flag, resulting in severe performance degradations when handling larger strings of HTML. The solution is to manually trim the strings via a combination of String#indexOf and String#substring. * removeWindowsFragments: bail early if no StartFragment found
Description
Copy-pasting a not-so-large HTML document takes more than 20 seconds.
A same issue has already been reported, but I have created a new issue to isolate the problem.
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
The following gif is when copy-and-pasting https://docusaurus.io/docs content.
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: