perf(RenderHTML): reduce HTML post-processing from 6 passes to 3#90305
Conversation
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
Hoist 4 inline regex literals to module-level constants (eliminates per-call recompilation) and merge related pairs of replaceAll calls: - Bracket unescaping: 2 literal replaceAlls → 1 regex pass - Emoji tag deduplication: 2 regex replaceAlls → 1 combined regex - <br> cleanup inside <ul>: 2 regex replaceAlls → 1 combined regex Benchmark on a ~109 KB synthetic payload: ~31% throughput improvement. Co-authored-by: Cursor <cursoragent@cursor.com>
c879d72 to
ee0a5da
Compare
|
no product review needed |
|
@tylerkaraszewski Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ee0a5dac72
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // Strip orphaned <br/> tags inside <ul> that would render as extra empty bullets | ||
| .replaceAll(/<br\s*\/?>\s*(<\/ul>)/gi, '$1') | ||
| .replaceAll(/(<\/li>)\s*<br\s*\/?>\s*(?=<(?:li|\/ul)>)/gi, '$1') | ||
| .replaceAll(RE_BR_CLEANUP, '$1$2') |
There was a problem hiding this comment.
Preserve cleanup for consecutive list breaks
When a list contains consecutive orphaned breaks before the closing </ul> (for example from pasted/blank-line list HTML like </li><br><br></ul>), the merged single-pass regex only removes the last <br> and leaves </li><br></ul>. The previous two-pass logic first removed the <br> before </ul> and then removed the newly exposed <br> after </li>, so this reintroduces the extra empty bullet the cleanup is meant to prevent.
Useful? React with 👍 / 👎.
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safari |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 @tylerkaraszewski has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/tylerkaraszewski in version: 9.3.73-0 🚀
Bundle Size Analysis (Sentry): |
|
|
|
🚀 Deployed to staging by https://github.com/tylerkaraszewski in version: 9.3.73-0 🚀
Bundle Size Analysis (Sentry): |
|
No help site changes required. This PR is a pure internal performance optimization (consolidating regex passes in |
|
🚀 Deployed to production by https://github.com/Beamanator in version: 9.3.73-4 🚀
|
Explanation of Change
Reduces the number of sequential string traversals in
RenderHTML'suseMemofrom 6 down to 3, and eliminates 4 inline regex literals that were being recompiled on every call.What changed:
&#91;→[,&#93;→]): 2 literalreplaceAllcalls merged into 1 regex pass usingRE_BRACKET_ESCAPE = /&#9[13];/greplaceAllcalls merged into 1 combined alternation patternRE_EMOJI_OPEN_OR_CLOSE<br>cleanup inside<ul>: 2 separate regexreplaceAllcalls merged into 1 combined alternation patternRE_BR_CLEANUPBenchmark (109 KB synthetic HTML payload, 5000 iterations):
Correctness verified: both approaches produce byte-identical output on a payload containing all three replacement cases.
To ground this in user experience - let's say the user has 200 messages loaded. ~0.08ms per message isn't much, but across 200 messages that's ~16ms, which is the maximum amount of time you can spend per frame to keep 60fps. If messages re-render multiple times, then the speedup has higher amortized value.
Fixed Issues
$
Tests
Open a chat, send a message with:
[and]characters — verify brackets render correctly- item) — verify no extra blank bullets appearOffline tests
N/A — this is a pure string-processing optimisation with no network interaction.
QA Steps [No QA]
Same as Tests above.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
web.mov