Skip to content

fix: isolate JSDOM parsing in child process to prevent memory leak#67

Merged
luispabon merged 1 commit into
masterfrom
memory-analysis
Jun 17, 2026
Merged

fix: isolate JSDOM parsing in child process to prevent memory leak#67
luispabon merged 1 commit into
masterfrom
memory-analysis

Conversation

@luispabon

Copy link
Copy Markdown
Collaborator

JSDOM leaks ~1.6MB of non-GC-able memory per window/document creation. Over thousands of requests this caused multi-GB RSS growth. The leak is fundamental to JSDOM's C++ internals — window.close() and forced GC cannot reclaim it.

Move all JSDOM/Readability/DOMPurify work into a child process that self-recycles every 500 parses. On termination the OS reclaims all leaked memory. Main process RSS stays flat at ~125MB regardless of request volume (verified at 10K requests, 0 failures).

JSDOM leaks ~1.6MB of non-GC-able memory per window/document creation.
Over thousands of requests this caused multi-GB RSS growth. The leak is
fundamental to JSDOM's C++ internals — window.close() and forced GC
cannot reclaim it.

Move all JSDOM/Readability/DOMPurify work into a child process that
self-recycles every 500 parses. On termination the OS reclaims all
leaked memory. Main process RSS stays flat at ~125MB regardless of
request volume (verified at 10K requests, 0 failures).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@luispabon

Copy link
Copy Markdown
Collaborator Author

Closes #35

@luispabon luispabon merged commit d8970ea into master Jun 17, 2026
2 of 3 checks passed
@luispabon luispabon deleted the memory-analysis branch June 17, 2026 21:41
@luispabon luispabon restored the memory-analysis branch June 17, 2026 21:45
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