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

small CChunkData write improvement #216

Merged
merged 2 commits into from
Oct 31, 2024
Merged

small CChunkData write improvement #216

merged 2 commits into from
Oct 31, 2024

Conversation

Alvsch
Copy link
Contributor

@Alvsch Alvsch commented Oct 30, 2024

Description

  • Replaced the HashMap in CChunkData::write with a Vec
  • Added profiling profile

Even though Vec has a worse time complexity for this, the HashMap overhead is worse for performance

Testing

Performance profiling was done using cargo-flamegraph.
If this breaks something I'll be genuinely surprised.

Checklist

Things need to be done before this Pull Request can be merged.

  • Code is well-formatted and adheres to project style guidelines: cargo fmt
  • Code does not produce any clippy warnings cargo clippy

palette.iter().enumerate().for_each(|(i, id)| {
palette_map.insert(*id, i);

let mut palette_ids = Vec::with_capacity(palette.len());

Choose a reason for hiding this comment

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

You could probably improve this by removing this Vec and using a lazy iterator instead. This vec seems to only be used for an iterator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, reusing the palette Vec works the same. No need to have the palette_ids Vec

@Snowiiii
Copy link
Owner

I tested the changes on pre-generated worlds and our own Chunk gen and can confirm that everything works.
Thanks @Alvsch

@Snowiiii Snowiiii merged commit 3f2bbcc into Snowiiii:master Oct 31, 2024
9 checks passed
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.

3 participants