chore(message-parser): pre-screen, LRU cache, tldParse memo, async generator#40568
chore(message-parser): pre-screen, LRU cache, tldParse memo, async generator#40568ggazzo wants to merge 1 commit into
Conversation
- Skip Peggy for inputs with no markdown triggers (trivial text fast path). - LRU cache (512 entries, <=4KB inputs) for repeated parse(input, options). - LRU memo (256 entries) around tldts parse() in autoLink/autoEmail. - parseStream async generator: split top-level blocks via BlockSplitter and yield event loop between blocks for long inputs.
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| }; | ||
|
|
||
| export const parse = (input: string, options?: Options): Root => grammar.parse(input, options); | ||
| const MARKDOWN_TRIGGER = /[\r\n*_~`@#:<>|!+$\\[\]()\-]|\.[A-Za-z]|^\d+\.|[⌀-➿☀-⛿\uD800-\uDBFF]/; |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #40568 +/- ##
===========================================
+ Coverage 69.60% 69.61% +0.01%
===========================================
Files 3323 3326 +3
Lines 122610 122904 +294
Branches 21853 21940 +87
===========================================
+ Hits 85338 85563 +225
- Misses 33939 33973 +34
- Partials 3333 3368 +35
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
Summary
Performance optimizations for
@rocket.chat/message-parserwithout changing grammar behavior.parse(input, options). Composite key encodes relevant options. Repeated messages (system notifications, presets, common phrases) hit the cache instead of re-parsing.tldParsecalls inautoLinkandautoEmail. Same URL or email reused across messages skips the tldts work.parseStreamasync generator: top-level block splitter (BlockSplitter) feeds Peggy one block at a time and yields the event loop between blocks. Long inputs no longer block the main thread for the full parse duration.Notes
parse()API and AST output are unchanged. Cached entries are returned by reference — callers should not mutate the AST (matches existing assumptions;plain(...)objects were already shared internally).parseStreamis opt-in (new export). Falls back to whole-input parse when the input is short or contains constructs that span blocks (||block spoiler).parse/parseStreaminside a Web Worker — async generator only frees the event loop, not the CPU.BlockSplitteris no longer dead code;parseStreamnow consumes it.Bench
Benchmarks reuse the same input per task, so the LRU cache dominates after the first iteration. Numbers reflect cache-hit / pre-screen behaviour, not cold parsing speed:
**Hello world**repeated specials(worst-case)Cold parsing of new inputs is unchanged — gains depend on repeat rate of real workload.
Test plan
yarn testfrompackages/message-parser/— 34 suites, 634 tests passingparseStreaminto composer preview / large thread render path