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

Cache Cargo.toml read result if successful #20

Merged
merged 6 commits into from
Aug 2, 2022
Merged

Conversation

jplatte
Copy link
Contributor

@jplatte jplatte commented Jul 19, 2022

Closes #19.

Within ruma-client-api, this reduces compile time of cargo clean && cargo check --features client from around 20.5s to around 19s on my machine. Out of that time, around 8.5s are for dependencies that don't use proc-macro-crate, so the real improvement is probably closer to 12s => 10.5s (12.5%).

jplatte added 4 commits July 18, 2022 19:22
proc-macros should be deterministic, and although it shouldn't matter in
this specific case, using HashMaps is an easy way to introduce
non-determinism (through iteration order).
toml's Map type is backed by either BTreeMap or IndexMap depending on
the activated features, both of which are fully deterministic.
Copy link
Owner

@bkchr bkchr 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! Looks like some good results! Would be good that you try this one improvement that I have proposed, looking forward to the results!

src/lib.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated
struct Cache {
manifest_dir: String,
manifest_path: PathBuf,
manifest: Table,
Copy link
Owner

Choose a reason for hiding this comment

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

Before we merge this, could you try to directly cache all crate names. So, have a hash table here that maps from crate name to crate name in the cargo file? By all I mean all crates that are referenced in the cargo.toml. May also brings some improvements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I implemented this. I think there is actually a behavioral change though: When you have multiple dependencies on the same package, previously the first one in the order they were searched was used to determine the crate name, now it's the last one in the order they are iterated to build the package > crate mapping (because, AFAIK, when collect()ing a BTreeMap the last occurrence of any given key "wins").

I'm pretty sure those two orderings are the same the way I implemented it now, so when a package is depended on with different crate names, a different one will be returned from crate_name now. I think assume this acceptable, just wanted to spell it out.

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah that sounds right, but this is also some very niche use case that wasn't tested before.

Copy link
Owner

Choose a reason for hiding this comment

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

BTW, did that improve the performance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can benchmark again next week.

Copy link
Owner

Choose a reason for hiding this comment

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

Would be nice

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 change doesn't seem to have a measureable impact on performance.

Copy link
Owner

@bkchr bkchr 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! :)

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.

Feature request: Cache result of reading Cargo.toml
2 participants