fix(serializing): reuse larger pooled writers#1054
Open
sqdbruh wants to merge 1 commit into
Open
Conversation
Length-pooled writers can be stored under a larger capacity bucket than the requested length bucket. Reusing the nearest larger bucket prevents pooled writers from staying rooted in the static length pool under variable payload sizes.
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.
Summary
This changes
WriterPool.Retrieve(length)so it can reuse a writer from the closest larger length bucket when the exact bucket is empty.The exact-bucket path stays the same. The fallback only runs when there is no writer available for the requested bucket, and empty buckets are removed after popping.
Background
I ran into this on a long-running Minecraft-like server with chunk streaming and large, variable payload sizes. Each player reconnect caused FishNet to retain some memory even after all player-owned resources were cleaned up. After enough reconnects, memory usage kept climbing until the server eventually ran out of RAM.
The issue is that a writer can be returned to the length pool under a bucket based on its actual capacity, which may be larger than the bucket requested later. Since
Retrieve(length)only checked the exact bucket, larger cached writers could sit in_lengthPooland remain strongly referenced instead of being reused.Reusing the nearest larger bucket fixed the retained allocation growth in that workload and kept memory usage stable across repeated reconnects.