Skip to content

Comments

chore(sync-service): Reduce PublicationManager memory usage#3496

Merged
magnetised merged 3 commits intomainfrom
magnetised/issue-3492-publication-manager-memory
Nov 25, 2025
Merged

chore(sync-service): Reduce PublicationManager memory usage#3496
magnetised merged 3 commits intomainfrom
magnetised/issue-3492-publication-manager-memory

Conversation

@magnetised
Copy link
Contributor

@magnetised magnetised commented Nov 25, 2025

Track state using just the table oid, not an {oid, {schema, table}} tuple and maintain a separate map of oid => {schema, table}.

Also build initial state in an ephemeral task so that we immediately garbage collect the results of loading the shape status table into RAM.

On a system with 150,000 defined shapes, this reduces the initial memory usage of PublicationManager from a steady state ~70MB (~270MB before GC) to a consistent ~21MB.

Also found and fixed a bug when cleaning relations -- we missed an argument change in the call to ShapeCleaner.cleanup_shapes_async/2 -- and fixed the behaviour of waiting for publication updates when failing (the start time was re-calculated every attempt, so the test never timed out).

Fixes #3492

@codecov
Copy link

codecov bot commented Nov 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.39%. Comparing base (c28e8ed) to head (fa41167).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3496      +/-   ##
==========================================
+ Coverage   75.17%   75.39%   +0.21%     
==========================================
  Files          51       51              
  Lines        2743     2743              
  Branches      408      409       +1     
==========================================
+ Hits         2062     2068       +6     
+ Misses        679      673       -6     
  Partials        2        2              
Flag Coverage Δ
electric-telemetry 22.71% <ø> (ø)
elixir 57.74% <ø> (+0.35%) ⬆️
elixir-client 74.47% <ø> (+0.52%) ⬆️
packages/experimental 87.73% <ø> (ø)
packages/react-hooks 86.48% <ø> (ø)
packages/typescript-client 93.15% <ø> (+0.16%) ⬆️
packages/y-electric 55.12% <ø> (ø)
typescript 87.51% <ø> (+0.12%) ⬆️
unit-tests 75.39% <ø> (+0.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@magnetised magnetised force-pushed the magnetised/issue-3492-publication-manager-memory branch from e9d5580 to ad77e7c Compare November 25, 2025 12:09
Track state using just the table oid, not a {oid, {schema, table}} tuple
and maintain a separate map of oid => {schema, table}.

Also build initial state in an ephemeral task so that we immediately
garbage collect the results of loading the shape status table into RAM.

On a system with 150,000 defined shapes, this reduces the initial memory
usage of PublicationManager from a steady state ~70MB (~270MB before GC)
to a consistent ~21MB.

Also found and fixed a bug when cleaning relations -- we missed an
argument change in the call to ShapeCleaner.cleanup_shapes_async/2 --
and fixed the behaviour of waiting for publication updates when failing
(the start time was re-calculated every attempt, so the test never timed
out).

Fixes #3492
@magnetised magnetised force-pushed the magnetised/issue-3492-publication-manager-memory branch from ad77e7c to e23dafa Compare November 25, 2025 12:22
@magnetised magnetised merged commit 65edd9f into main Nov 25, 2025
47 checks passed
@magnetised magnetised deleted the magnetised/issue-3492-publication-manager-memory branch November 25, 2025 14:59
@github-actions
Copy link
Contributor

This PR has been released! 🚀

The following packages include changes from this PR:

Thanks for contributing to Electric!

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.

PublicationManager.RelationTracker high memory usage

2 participants