Skip to content
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

[PERF] BundleWriter: Improve performance #534

Merged
merged 5 commits into from
Oct 22, 2020
Merged

[PERF] BundleWriter: Improve performance #534

merged 5 commits into from
Oct 22, 2020

Conversation

matz3
Copy link
Member

@matz3 matz3 commented Oct 21, 2020

The ENDS_WITH_NEW_LINE RegExp is quite slow on large strings.
Therefore the "endsWithNewLine" state is computed after every modification
to the "buf" in order to improve performance.

Measurements

Based on sap.m build in SAP/openui5@0d95920

Command Mean [s] Min [s] Max [s]
2a51943 (master)
ui5 build --exclude-task="*" --include-task=generateLibraryPreload
15.077 ± 0.355 14.476 15.499
713acb3 (BundleWriter-perf)
ui5 build --exclude-task="*" --include-task=generateLibraryPreload
12.393 ± 0.334 11.883 12.913

The ENDS_WITH_NEW_LINE RegExp is quite slow on large strings.
Therefore the "endsWithNewLine" state is computed after every modification
to the "buf" in order to improve performance.
@RandomByte
Copy link
Member

I like this

@coveralls
Copy link

coveralls commented Oct 21, 2020

Coverage Status

Coverage increased (+0.08%) to 92.899% when pulling cc09738 on BundleWriter-perf into 2a51943 on master.

}
if ( writeBuf.length >= 1 ) {
this.buf += writeBuf;
this.endsWithNewLine = ENDS_WITH_NEW_LINE.test(writeBuf);
Copy link
Member

Choose a reason for hiding this comment

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

This can give wrong results when write is called with blanks or tabs only. In that case, the old endsWithNewLine flag must be taken into account as well.

Correct would be something like

  ENDS_WITH_NEW_LINE.test(writeBuf) || (this.endsWithNewLine && !writeBuf.trim())

Instead of the trim(), one could use another RegExp /^[ \t]*$/

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds right 👍🏻
As there were no dedicated unit tests, I've added one to cover the whole class.

Co-authored-by: Merlin Beutlberger <[email protected]>
@matz3 matz3 dismissed codeworrior’s stale review October 22, 2020 14:35

Solved as suggested

@matz3 matz3 merged commit 750b43e into master Oct 22, 2020
@matz3 matz3 deleted the BundleWriter-perf branch October 22, 2020 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants