Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gossip(gossip,net,sync,tvu): Channel(Managed -> Unmanaged) overhaul #165

Closed
wants to merge 1 commit into from

Conversation

InKryption
Copy link
Contributor

Send unmanaged arraylists over channels instead of managed ones, reducing redundant bytes used for duplicate allocator interfaces. Also use some out-parameters instead of returning arraylists in some cases.

@InKryption InKryption requested review from dnut and 0xNineteen June 7, 2024 04:32
@InKryption InKryption self-assigned this Jun 7, 2024
peers: []ContactInfo,
) error{OutOfMemory}!struct { valid_peers: std.ArrayList(usize), pings: std.ArrayList(PingAndSocketAddr) } {
peers: []const ContactInfo,
out: struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you change this to pass in the arraylist's as a parameter vs return them? seems like everywhere we use it we init&deinit so we dont really take advantage of this approach

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing it in like this avoids the anonymous struct return, which has to always be deconstructed; another route would be to return a tuple which we could easily deconstruct at the call-site, but it'd be two arraylists. Obviously they're different types, but I dislike the visual ambiguity, so I opted for turning these into out parameters; another consideration is that it would allow us to more easily re-use a buffer in the future if the opportunity ever came about.

@@ -345,14 +357,6 @@ pub const GossipService = struct {
exitAndJoin(self.exit, thread);
};

const responder_thread = try Thread.spawn(.{}, socket_utils.sendSocket, .{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can see the advantages of grouping the socket threads together - but i prefer the order we had it before because it shows the flow of data better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -56,7 +56,7 @@ const globalRegistry = @import("../prometheus/registry.zig").globalRegistry;
const GetMetricError = @import("../prometheus/registry.zig").GetMetricError;
const Counter = @import("../prometheus/counter.zig").Counter;

const PacketBatch = ArrayList(Packet);
const PacketBatch = std.ArrayListUnmanaged(Packet);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im concerned removing the alloc out of the arraylist could lead to freeing the data with the wrong allocator at some point in time - we want to reduce the amount of dev overhead/thinking required to make changes to the codebase - and it is nice to have but i dont see any significant improvement from this change

Copy link
Contributor Author

@InKryption InKryption Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is my opinion that this actually reduces the mental overhead when you consider the fact that the allocator used to alloc/free the packet batches going through a channel can now be centralized in one specific place, instead of needing to track down the origin of each packet batch through the multithreaded access of a given channel. This also has the effect that the lifetime of any allocator used for this purpose is now more obvious, which will allow us to avoid accidental UAF of allocator interfaces.

Edit: also, just to note, freeing with the wrong allocator is not a huge concern when you consider the fact that GPA actually catches invalid frees.

Send unmanaged arraylists over channels instead of managed ones,
reducing redundant bytes used for duplicate allocator interfaces.
Also use some out-parameters instead of returning arraylists in
some cases.
@InKryption InKryption force-pushed the ink/managed-to-unmanaged-over-channels branch from 598547e to d1167ef Compare June 10, 2024 17:12
@InKryption
Copy link
Contributor Author

Closing due to some more complex incompatibilities of this change with the recent repair_service PR (#136). We can revisit this idea & conversation at a later date.

@InKryption InKryption closed this Jun 10, 2024
@InKryption InKryption deleted the ink/managed-to-unmanaged-over-channels branch June 10, 2024 17:28
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.

2 participants