Skip to content

perf(app): mine Event Patterns with the TypeScript Drain port instead of Pyodide - #6

Draft
karljohang wants to merge 4 commits into
claude/drain-ts-tokenizerfrom
claude/drain-ts-event-patterns
Draft

karljohang wants to merge 4 commits into
claude/drain-ts-tokenizerfrom
claude/drain-ts-event-patterns

Conversation

@karljohang

@karljohang karljohang commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

Summary

Event Patterns ran drain3 inside Pyodide on the main thread: a 14 MB Python runtime that froze the page for up to 760 ms on first use (1.3 s on a 4× throttled CPU). It now mines with the TypeScript Drain port in common-utils, which the CLI and MCP server already use. It gives the same clusters and templates as drain3, and it mines 10,000 lines in under 50 ms.

  • Date masks: the port masks dates by default. The app clears the masks to match drain3's default config; otherwise a masked date is one token where the log has three, which misaligns the pattern display, Denoise, and pattern filters. mineEventPatterns.test.ts checks that dates stay unmasked.
  • Pattern filters split on Python's str.split() whitespace to match drain3. They now split on JS \s, like the miner, so an event with a BOM between words no longer falls out of an include filter for its own pattern. Filters saved under drain3 still apply and still read back as pattern filters. The filter options now sit next to the shared delimiter list in drainDelimiters.ts, so the miner and the filters can't drift apart again.
  • patternFilter.test.ts mines JSON lines and dated lines and checks that every template's filter and Denoise matcher match every line mined into it.

_document.tsx still loads pyodide.js; a follow-up removes it and the unused runtime and wheels.

Screenshots or video

No visual change.

How to reproduce

Starting point: yarn app:dev:local connected to the demo server (onboarding → "Connect to Demo Server").

On main:

  1. Open DevTools → Network and load /search with a logs source.
  2. Click the Event Patterns tab. pyodide.asm.wasm, python_stdlib.zip, and the drain3 and jsonpickle wheels download, and the page freezes while they load and mining runs.

On this branch:

  1. Click Event Patterns. None of those files load, and patterns appear without the freeze.
  2. Hover a pattern and click Filter for this pattern. Every result matches it.

How to test on Vercel preview

Preview routes: /search

Steps:

  1. Open /search with the demo logs source selected.
  2. Click the "Event Patterns" tab.
  3. Verify the pattern table shows patterns with counts.
  4. Hover the first pattern row and click "Filter for this pattern".
  5. Verify the search results are not empty and each row matches the selected pattern.

References

  • Linear Issue:
  • Related PRs:

drewhammond and others added 4 commits December 4, 2026 15:58
… of Pyodide

Event Patterns loaded a 14 MB Python runtime and ran drain3 in it on the
main thread, freezing the page for up to 760 ms on first use (1.3 s on a
4x throttled CPU). The TypeScript port the CLI and MCP server already use
gives the same clusters and templates and mines 10,000 lines in under
50 ms.

The port masks dates by default since ClickHouse#3551, so the app clears the masks
to match drain3's default config. With punctuation delimiters a masked
date is one word where the log has three, which would misalign the
pattern display, Denoise and pattern filters. mineEventPatterns.test.ts
checks that dates stay unmasked.
Event Patterns now mines with the TypeScript Drain port, which splits on JS
`\s`. Pattern filters still split on Python's str.split() whitespace, so an
event with a BOM between words fell out of an include filter of its own
pattern, and one with \x1e or NEL matched a pattern it was never mined into.
Filters built before this change still filter the same and still read back
as pattern filters.

The filter options now sit next to the shared delimiter list in
drainDelimiters.ts. The list was already shared, but the filter's
whitespace was set on its own, so nothing moved it when the miner did.
…mplate

patternFilter.test.ts mines two JSON lines and two that start with dates,
and checks that every template's filter and Denoise matcher match every line
mined into it. Putting back the default date masks fails both tests.
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.

2 participants