#13300
[Design] Streaming and worker isolation for Playwright traces, WebSourceMapFetcher, CaptureJson, Asset Catalog, and AnalysisView files
Before submitting
- I searched the open and closed issues and pull requests for a related discussion (#13281, #13275).
- I understand the contribution scope must be reviewed before integration; open questions are welcome here.
- This discussion does not include credentials, private samples, or sensitive target data.
Decision needed
Should REA move remaining heavy main-thread capture, source-map, asset-catalog, and AnalysisView I/O onto bounded worker/streaming pipelines and indexed/retained Evidence views:
- Worker isolation & selective line skipping for
inspect_playwright_trace(avoiding full object materialization and64xheap headroom checks on multi-MB discardedframe-snapshotDOM lines), - Worker execution & lazy/on-demand source-map decoding for
WebSourceMapFetcher.normalizeSourceMapandWebModuleTraceService(moving up to 64 MiB JSON parse, VLQ mapping expansion, and fullsourcesContentBabel AST parsing off the parent event loop, plus avoiding 50 MB inlinesource_map_textembedding intrace_web_source_locationEvidence.rawResult), - Single-pass streaming JSON & deduplicated HAR bodies in
CaptureJson/HarCapture(avoidingjsonc-parserper-tokenMap/LosslessNumber/JSON.parseoverhead and 2x base64 duplication betweenreportedandbinary_fields), and - Indexed/retained paging across
AnalysisViewService(--evidence-bundle/evidence-file) andinspect_asset_catalog(instead of re-reading/re-parsing 100 MB Evidence JSON or re-runningassetutil+ Interface Builder decoding on every page)?
Context and evidence
Source-derived analysis of REA's JavaScript, Browser, Capture, Artifact, and AnalysisView pipelines:
- Playwright trace (
src/browser/history/playwrightTrace/TraceStream.ts:146-225,TraceEventProjection.ts:106-114):- Runs in-process on the main event loop without a worker timeout.
- Calls
readRecord(line.bytes)(fullparseCaptureJsonparse + heap headroom multiplier check) on every NDJSON line before inspectingraw.type, even thoughprojectTraceEvent/selectedEventimmediately discardsframe-snapshotDOM snapshots (typically the largest lines in real traces).
- Web source maps & module tracing (
src/browser/WebSourceMapFetcher.ts:1028-1316,src/application/WebSourceLocationService.ts,src/application/WebModuleTraceService.ts):normalizeSourceMap(WebSourceMapFetcher.ts:1028-1236) parses up to 64 MiB source map JSON, decodes all VLQ segments, charges per-segmentmappingRowBytesandJSON.stringify(edge)budgets, and runs synchronous BabelparseJavaScriptSourceover every embeddedsourcesContentfile (originalModuleEdges,lines 1244-1316) directly on the parent event loop — blocking timers and MCP cancellation delivery.trace_web_source_locationretains fullsource_map_textinline insideEvidence.rawResult, causing full canonical serialization, SHA-256 hashing, and cloning per point query.
- Historical capture JSON (
src/browser/history/CaptureJson.ts,HarCapture.ts):CaptureJsonbuilds fullMap+Object.fromEntries+LosslessNumber+ per-stringJSON.parsetrees over entire HAR/qlog files viajsonc-parservisit(), andHarCaptureclones the tree for AJV validation and retains base64 bodies twice (reported.response.content.textandbinary_fields[].content_base64), amplifying memory andmax_reply_bytesfailures.
- Repeated cold reloads on paginated inspections (
src/artifacts/apple/AppleAssetCatalogAnalysis.ts:102-200,src/application/analysisView/AnalysisViewService.ts):inspect_asset_catalogre-walks.app, re-runs/usr/bin/assetutil, and re-decodes all Interface Builder.nib/.storyboardcfiles on everyoffset/limitpage call.inspect_analysis_viewonevidence-file/--evidence-bundlere-reads, re-parses, validates, and deep-freezes the full Evidence JSON from disk on every paginated page/view call, andapi-surface/environment-manifest/environment-stateviews re-run accumulation/simulation across calls.
Expected interaction with targets
- Read existing files or captured data (local captures, source maps, asset catalogs, and Evidence files under existing read-only bounds).
Boundary details (optional)
- Preserving strict JSON structural checks (duplicate keys, nesting depth, parser node bounds, exact integer precision) and incomplete/malformed diagnostics in Playwright/HAR/qlog must remain equivalent when introducing lightweight pre-filters or streaming parsers.
- For
inspect_asset_catalogandAnalysisViewService, any retained state or index must verify file/target freshness (dev,ino,size,mtime/ctimeor digest verification) before reuse.
Options and tradeoffs
- Playwright trace: Peek top-level
"type"and validate JSON well-formedness/depth for discardedframe-snapshotevents without allocating full JS object graphs, and run the decoder inside a supervised worker with an explicit timeout and time/byte-based yielding. - Web source maps &
WebModuleTraceService: ExecutenormalizeSourceMapandWebModuleTraceServiceBabel parsing in the existing worker pool, decode only queried lines lazily on point lookups, and store large source-map text by digest/reference rather than inline per lookup inEvidence.rawResult. - Asset catalog &
AnalysisView: Aligninspect_asset_catalogwith retained Evidence +inspect_analysis_view(or verify freshness cleanly), and provide an indexed/verified reader for repeated paginatedevidence-filereads.
Verification available so far
- Idea only; I need help defining checks
Success criteria and open questions
- Should
trace_web_source_locationomit full inlinesource_map_textfromEvidence.rawResultin favor of a digest/byte summary or opt-in flag? - Can
inspect_asset_catalogtransition to the shareddetail+inspect_analysis_viewpattern used byinventory_artifactsandanalyze_javascript_application? - What strict JSON validation invariants (
duplicate keys, large-integer fidelity) must a streaming fast-path forCaptureJson/TraceStreampreserve?
References
- Related issue: #13281, #13275
src/browser/history/playwrightTrace/TraceStream.ts:146-225src/browser/history/playwrightTrace/TraceEventProjection.ts:106-114src/browser/WebSourceMapFetcher.ts:1028-1316src/artifacts/apple/AppleAssetCatalogAnalysis.ts:102-200src/application/analysisView/AnalysisViewService.ts
Activity
0No activity yet.