Skip to content

Voices experimentation#1

Draft
eadwright wants to merge 3 commits intokujon:mainfrom
eadwright:faster_voices
Draft

Voices experimentation#1
eadwright wants to merge 3 commits intokujon:mainfrom
eadwright:faster_voices

Conversation

@eadwright
Copy link

@eadwright eadwright commented Aug 20, 2023

  • Cargo.toml hacked so we can have two main() entry points, one bench for crude benchmarking
  • Some changes made to Voices, making it generic (needed in earlier testing, probably no longer needed). Note passing Key enums by value is cheap, we don't need references.
  • Voices2 is where the action is
  • bench.rs contains the simple benchmark, for better or worse
  • The code can pack the key ordinal into a u128 as there are fewer than 128 keys. If that were not the case it'll blow up.

This code isn't polished and is meant to inspire ideas.

Note we can derive an enum ordinal using a crate, but Key was defined in a dependency so we can't, hence the hack with 🤭 unsafe.

@eadwright eadwright marked this pull request as draft August 20, 2023 15:40
}
}

fn new_with_time(item: T, creation_time: SystemTime) -> Self {
Copy link
Author

Choose a reason for hiding this comment

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

At one point I wanted to specify time in my tests, then I realised input order probably suffices.

}
self.voices.insert(WithCreationTime::new(key), sink);
self.voices.get(&WithCreationTime::new(key))
let w = WithCreationTime::new_with_time(key, time);
Copy link
Author

Choose a reason for hiding this comment

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

I think the original code calling the constructor twice may be a bug? You may end up with different timestamps in each, and you want your map lookup to be based on the Key only I believe, not the time.

use rdev::Key;

fn get_ordinal(key: Key) -> u8 {
let ptr_to_option = (&key as *const Key) as *const u8;
Copy link
Author

Choose a reason for hiding this comment

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

The underlying representation for an enum with under 256 variants starts with an ordinal byte, guaranteed. Get that number!

@eadwright
Copy link
Author

Inspiring?

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.

1 participant