Skip to content

Removed "Meta" field from syn_registry_entry (syn_registry_by_name table) to reduce RAM usage#89

Open
emikodes wants to merge 1 commit into
ostinelli:masterfrom
emikodes:feature/removed_spec_duplication
Open

Removed "Meta" field from syn_registry_entry (syn_registry_by_name table) to reduce RAM usage#89
emikodes wants to merge 1 commit into
ostinelli:masterfrom
emikodes:feature/removed_spec_duplication

Conversation

@emikodes
Copy link
Copy Markdown

Spawning a child process currently requires the insertion of two tuples, respectively in the syn_registry_by name and syn_registry_by_pid ETS.

In the current implementation, the Meta field is fully duplicated in both tables:

-type syn_registry_entry() :: {
    Name :: term(),
    Pid :: pid(),
    **Meta :: term(),**
    Time :: integer(),
    MRef :: undefined | reference(),
    Node :: node()
}.

-type syn_registry_entry_by_pid() :: { %%kept only here (First element of tuple becomes a key in ETS)
    Pid :: pid(),
    Name :: term(),
    **Meta :: term(),**
    Time :: integer(),
    MRef :: undefined | reference(),
    Node :: node()
}.

If Meta is a large piece of information, this duplication causes unnecessary memory usage.

In this PR, the syn_registry_by_name table has been shrinked by removing the Meta field.

Read operations now require a double-jump lookup:
1.Find the Pid from the Name (in syn_registry_by_name).
2.Find the Meta from the Pid (in syn_registry_by_pid).

This optimization allows to save up to 50% of the ETS Usage. Also, Write and Delete operations become marginally lighter due to less memory allocation and copying.

Executing a little "StressTest" script, which spawns 500k processes and shows the memory footprint, allows to visualize the memory reduction:

Before:

iex(2)> StressTest.run()
Spawning 500000 processes.

Initial BEAM memory:
   - Name Table: 0.0 MB
   - PID Table:  0.0 MB
   - ETS:   0.93 MB


Spawn completed
Elapsed time: 9.188 seconds
   - Name Table: 640.81 MB
   - PID Table:  640.81 MB
   - ETS:   1289.41 MB
Screenshot 2026-05-21 164505

After:

iex(3)> StressTest.run()
Spawning 500000 processes.
Initial BEAM memory:
   - Name Table: 0.0 MB
   - PID Table:  0.0 MB
   - ETS:   0.98 MB


Spawn completed
Elapsed time: 10.008 seconds
   - Name Table: 68.6 MB
   - PID Table:  640.81 MB
   - ETS:   717.21 MB
Screenshot 2026-05-21 165315

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