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

Refactor RenetClient so channels are accessed more efficiently #154

Closed
wants to merge 2 commits into from

Conversation

UkoeHB
Copy link
Contributor

@UkoeHB UkoeHB commented Mar 4, 2024

Problem

Currently you need a HashMap lookup to access channels in clients. On the server these hashmaps are accessed for every packet received.

Solution

Use a Vec to store the channels so lookups are fast. Channels should be generated in monotonically increasing order, so in general there won't be any empty entries. Even if there are empty entries, at most 256 channels can be created, so the memory cost of bad channel assignment is not significant.

Follow-up

  • Reading packets requires a HashMap lookup for the target client. This is inefficient if a client has multiple packets, so a mutating iterator is preferable. Even better would probably be a global mutating iterator that traverses the client map.

Copy link
Contributor

@Shatur Shatur left a comment

Choose a reason for hiding this comment

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

Nice change!

But I would probably remove channel_id from ChannelConfig and automatically assign it based on the index. This way we ensure that channels have sequenced IDs.

@UkoeHB
Copy link
Contributor Author

UkoeHB commented Mar 4, 2024

But I would probably remove channel_id from ChannelConfig and automatically assign it based on the index. This way we ensure that channels have sequenced IDs.

That would be a breaking change, this is just a refactor PR.

@UkoeHB UkoeHB closed this Dec 23, 2024
@UkoeHB UkoeHB deleted the optimize_client branch December 23, 2024 19:34
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