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

Optimize event ids by splitting them up by server/client and reliable/unreliable #143

Open
wants to merge 3 commits into
base: 0.6.x
Choose a base branch
from

Conversation

nezuo
Copy link
Contributor

@nezuo nezuo commented Dec 31, 2024

Currently, all events and functions share event ids in the same pool. This is unnecessary and optimizing it will allow for more events/functions before needing to increase the bytes required for the event id.

To give an example, reliable events and functions are never sent through the unreliable remote. This means we can have separate pools of ids for reliable and unreliable.

@nezuo
Copy link
Contributor Author

nezuo commented Dec 31, 2024

Event ids used to start at 1 instead of 0. I'm not sure why this was the case, let me know if I'm missing something!

@sasial-dev sasial-dev requested a review from jackdotink January 6, 2025 02:02
Comment on lines +35 to +67
pub fn server_reliable_count(&self) -> usize {
let reliable_count = self
.evdecls
.iter()
.filter(|evdecl| evdecl.from == EvSource::Client && evdecl.evty == EvType::Reliable)
.count();

reliable_count + self.fndecls.len()
}

pub fn server_unreliable_count(&self) -> usize {
self.evdecls
.iter()
.filter(|evdecl| evdecl.from == EvSource::Client && evdecl.evty == EvType::Unreliable)
.count()
}

pub fn client_reliable_count(&self) -> usize {
let reliable_count = self
.evdecls
.iter()
.filter(|evdecl| evdecl.from == EvSource::Server && evdecl.evty == EvType::Reliable)
.count();

reliable_count + self.fndecls.len()
}

pub fn client_unreliable_count(&self) -> usize {
self.evdecls
.iter()
.filter(|evdecl| evdecl.from == EvSource::Server && evdecl.evty == EvType::Unreliable)
.count()
}
Copy link
Member

Choose a reason for hiding this comment

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

why are we doing this instead of having separate reliable and unreliable counts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This allows for more events before increasing the ids. Imagine 256 reliable client to server events and 256 reliable server to client events. With how I've done it, that only needs a u8. If we combined them, it would need a u16. It's possible to separate them because the events are one-way.

I might have misunderstood the question though.

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