-
Notifications
You must be signed in to change notification settings - Fork 23
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
Conversation
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.
I like this |
lib/lbt/bundle/BundleWriter.js
Outdated
} | ||
if ( writeBuf.length >= 1 ) { | ||
this.buf += writeBuf; | ||
this.endsWithNewLine = ENDS_WITH_NEW_LINE.test(writeBuf); |
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.
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]*$/
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.
Sounds right 👍🏻
As there were no dedicated unit tests, I've added one to cover the whole class.
Co-authored-by: Merlin Beutlberger <m.beutlberger@sap.com>
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
ui5 build --exclude-task="*" --include-task=generateLibraryPreload
ui5 build --exclude-task="*" --include-task=generateLibraryPreload