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

Replace hash maps with fast hash maps #2150

Merged
merged 3 commits into from
Jun 15, 2018
Merged

Conversation

grovesNL
Copy link
Contributor

@grovesNL grovesNL commented Jun 15, 2018

Fixes #2148
PR checklist:

  • make succeeds (on *nix)
  • make reftests succeeds
  • tested examples with the following backends: Metal/GL/DX12/Vulkan

Changes:

  • Replaced HashMap with FastHashMap type (uses FxHash)
  • Changed Queues to use a Vec instead of HashMap. It doesn't seem like a HashMap is necessary here, and the family ID is already present within the queue group, if I understand correctly. But this seems trivial overall because this shouldn't be a hot path ever.
  • mtl: Changed bindings to use a Vec (holey, filled with potentially a lot of None) indexed by binding. Not sure if this is the best approach but it should provide fast iteration and lookup by binding

Overall this seems to give a pretty good improvement in Dota 2 as far as I can tell from profiling. I don't have precise benchmarks.

@grovesNL grovesNL changed the title Replace hash maps with fast hash maps WIP: Replace hash maps with fast hash maps Jun 15, 2018
@grovesNL grovesNL changed the title WIP: Replace hash maps with fast hash maps Replace hash maps with fast hash maps Jun 15, 2018
@grovesNL grovesNL changed the title Replace hash maps with fast hash maps [WIP] Replace hash maps with fast hash maps Jun 15, 2018
@grovesNL grovesNL changed the title [WIP] Replace hash maps with fast hash maps Replace hash maps with fast hash maps Jun 15, 2018
@grovesNL grovesNL requested a review from kvark June 15, 2018 06:16
@fintelia
Copy link
Contributor

Using VecMap<T> might be preferable to using Vec<Option<T>> directly. I'm not sure whether or not the slightly nicer interface would justify an additional dependency though.

Copy link
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

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

Thank you for optimizing this! I'm looking forward to see how Dota improves :)
In the meantime, there is a few comments to address and CI to fix before we proceed with merging.

@@ -6,17 +6,19 @@ use {conversions as conv, command, native as n};
use native;

use std::borrow::Borrow;
use std::collections::hash_map::{Entry, HashMap};
use std::collections::HashMap;
Copy link
Member

Choose a reason for hiding this comment

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

why this change? it's the same as the old code but more verbose

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I need to combine these again. Originally HashMap was removed entirely then I realized we still need it for the spirv_cross overrides

@@ -55,6 +56,9 @@ pub mod queue;
pub mod range;
pub mod window;

#[doc(hidden)]
pub mod auxil;
Copy link
Member

Choose a reason for hiding this comment

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

actually, it appears to me that backend has a very similar goal. Should we move the fast hashmap into backend?

@@ -12,6 +12,7 @@ extern crate core_graphics;
extern crate block;
extern crate smallvec;
extern crate spirv_cross;
extern crate fxhash;
Copy link
Member

Choose a reason for hiding this comment

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

why does Metal need this explicitly? I'd assume it to just use the types exported from hal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, just left it there accidentally

@grovesNL
Copy link
Contributor Author

CI failure seems unrelated, I'll rebase now

@kvark
Copy link
Member

kvark commented Jun 15, 2018

thanks!
bors r+

bors bot added a commit that referenced this pull request Jun 15, 2018
2150: Replace hash maps with fast hash maps r=kvark a=grovesNL

Fixes #2148
PR checklist:
- [X] `make` succeeds (on *nix)
- [X] `make reftests` succeeds
- [X] tested examples with the following backends: Metal/GL/DX12/Vulkan

Changes:
- Replaced `HashMap` with `FastHashMap` type (uses `FxHash`)
- Changed `Queues` to use a `Vec` instead of `HashMap`. It doesn't seem like a `HashMap` is necessary here, and the family ID is already present within the queue group, if I understand correctly. But this seems trivial overall because this shouldn't be a hot path ever.
- mtl: Changed bindings to use a `Vec` (holey, filled with potentially a lot of `None`) indexed by binding. Not sure if this is the best approach but it should provide fast iteration and lookup by binding

Overall this seems to give a pretty good improvement in Dota 2 as far as I can tell from profiling. I don't have precise benchmarks.

Co-authored-by: Joshua Groves <[email protected]>
@bors
Copy link
Contributor

bors bot commented Jun 15, 2018

@bors bors bot merged commit 5421247 into gfx-rs:master Jun 15, 2018
@grovesNL grovesNL deleted the fasthashmap branch June 15, 2018 22:14
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