Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I improve compile times when I have a large HashMap literal?

Tags:

rust

I have a very large HashMap of physical measurements (300k+ entries of 3-element tuples), which I'd like to keep as a HashMap (I could move it out to a SQLite DB and query it, but I'd rather not, for performance reasons). Including it as a literal makes compile times…long. Is there a better approach? Could I serialise it to disk in a binary format, and load it as a HashMap when the binary executes / the library is loaded? Developing and testing using a subset works fine, but I need the full data for production…

like image 824
urschrei Avatar asked Feb 05 '16 16:02

urschrei


1 Answers

So you're hardcoding a hash map? That seems to be a Perfect Hashing problem, see the https://github.com/sfackler/rust-phf crate.

As for the compile times, offload the hash table into a separate crate and Cargo will only recompile this crate when the hash table data changes.

like image 196
ArtemGr Avatar answered Nov 02 '22 01:11

ArtemGr