chore(sync-service): Reduce PublicationManager memory usage#3496
Merged
magnetised merged 3 commits intomainfrom Nov 25, 2025
Merged
chore(sync-service): Reduce PublicationManager memory usage#3496magnetised merged 3 commits intomainfrom
magnetised merged 3 commits intomainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
e9d5580 to
ad77e7c
Compare
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
ad77e7c to
e23dafa
Compare
alco
approved these changes
Nov 25, 2025
packages/sync-service/lib/electric/replication/publication_manager/relation_tracker.ex
Show resolved
Hide resolved
packages/sync-service/lib/electric/replication/publication_manager/relation_tracker.ex
Outdated
Show resolved
Hide resolved
Contributor
|
This PR has been released! 🚀 The following packages include changes from this PR: Thanks for contributing to Electric! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Track state using just the table
oid, not an{oid, {schema, table}}tuple and maintain a separate map ofoid => {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