Skip to content

Parse large CSVs off the main thread (PapaParse worker)#7

Merged
cybermejo merged 1 commit into
mainfrom
worktree-studio-csv-worker
Jun 18, 2026
Merged

Parse large CSVs off the main thread (PapaParse worker)#7
cybermejo merged 1 commit into
mainfrom
worktree-studio-csv-worker

Conversation

@cybermejo

Copy link
Copy Markdown
Owner

Summary

Parses large CSVs on a background worker so a big paste/upload no longer freezes the UI.

Why

parseCSV called Papa.parse synchronously on the main thread. A large file blocked rendering until parsing finished.

What changed

  • Enable PapaParse worker: true only when the input exceeds 512 KB. Small inputs keep the synchronous main-thread path — the worker's serialization overhead makes it slower for them, and the freeze only matters for large files.
  • The Promise contract and the normalizefilterenrich post-processing are unchanged (the worker only does the parse; enrichment still runs on the main thread on the parsed rows).

Safety / compatibility

  • Verified empirically: when no Worker global exists (Node / vitest), PapaParse falls back to synchronous parsing and still fires complete with correct rows — so existing tests and any non-browser use are unaffected.

Testing

Adds a >512 KB parse test (30k rows) that exercises the worker path end-to-end (full normalize/enrich pipeline, correct row count + values). 41 tests pass; build green.

parseCSV ran Papa.parse synchronously, so a big paste/upload froze the UI while
parsing. Enable worker:true above a 512KB threshold so large inputs parse on a
background thread; small inputs keep the synchronous main-thread path (the
worker's serialization overhead makes it slower for them).

PapaParse falls back to synchronous parsing when no Worker global exists
(verified in Node), so the existing tests and any non-browser use are unaffected.
The Promise contract and the normalize/enrich post-processing are unchanged.

Adds a >512KB parse test (30k rows) exercising the worker path. 41 tests green.
@cybermejo
cybermejo merged commit bf071fe into main Jun 18, 2026
4 checks passed
cybermejo pushed a commit that referenced this pull request Jun 18, 2026
PR #10 (config/query/api/cli split + __main__.py) had merged into its stacked
base branch but not into main, which still carried the flat tweet_scraper.py.
Bring the split to main. Touches only scraper/CI/docs — no Studio files, so the
PR #6/#7 Studio work is untouched. CLAUDE.md auto-merged (kept the PR #8 Studio
note + the split's python -m updates). Validation loop green: 65 tests, mypy on
the package, python -m tweet_scraper verified.
@cybermejo
cybermejo deleted the worktree-studio-csv-worker branch June 18, 2026 03:17
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.

1 participant