Endpoint conns default emits a multi‑hundred‑MB zero blob into the binary - #1
Merged
Conversation
Co-authored-by: Daeren <Daeren@users.noreply.github.com>
Member
|
good catch, thanks for the fix! |
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.
Description
Endpoint(cfg)declares:With game-sized limits (e.g.
max_connections = 64,channel_cap = 256,max_payload ≈ 1200, fragmentation on), eachSessionis on the order of ~2 MB. Zig materializes the field default as a constant, so the linked executable’s.rdatacontains roughly:max_connections × sizeof(Session)of zeros (often ~150–200 MB), while
.textstays well under 1 MB.This is unrelated to optimize mode (
Debug/ReleaseSafe/ReleaseFastall bloat). Runtime still needs a largeEndpointin memory by design (zero steady-state allocation); the bug is that the same table is also baked into the on-disk binary via the array default.Live slots are already initialized in
findOrAdd:Unused slots are never read (
used[]). The[_]SessionT{.{}} ** maxdefault is redundant for correctness and only hurts binary size.Minimal reproduction
Build with
zig build -Doptimize=ReleaseFast(or any optimize mode) and inspect the exe:.rdata≈ that size, ~99% zero bytes.textremains small(Exact size depends on
Config; the pattern appears as soon assizeof(Session) × max_connectionsis large.)Solution
In
src/proto/endpoint.zig, change theconnsfield default:No other call-site changes are required:
findOrAdd/connectToalready assignconns[i] = .{}and callsetup()before use.Endpoint{}/magnet.openleave idle slots uninitialized, which is fine whileused[i] == false.*Same pattern on Server.baselines, much smaller; optional follow-up (baselines: [max_clients]Inner = undefined)