use std::collections::HashMap;
use std::mem::size_of;
struct S {
_handlers: HashMap<usize, usize>,
}
fn main() {
println!("{}", size_of::<S>());
}
godot2:tmp jdm$ rustup override set nightly-2017-02-16
info: using existing install for 'nightly-2017-02-16-x86_64-apple-darwin'
info: override toolchain for '/private/tmp' set to 'nightly-2017-02-16-x86_64-apple-darwin'
nightly-2017-02-16-x86_64-apple-darwin unchanged - rustc 1.17.0-nightly (62eb6056d 2017-02-15)
godot2:tmp jdm$ rustc node.rs
godot2:tmp jdm$ ./node
40
godot2:tmp jdm$ rustup override set nightly-2017-02-17
info: using existing install for 'nightly-2017-02-17-x86_64-apple-darwin'
info: override toolchain for '/private/tmp' set to 'nightly-2017-02-17-x86_64-apple-darwin'
nightly-2017-02-17-x86_64-apple-darwin unchanged - rustc 1.17.0-nightly (668864d9e 2017-02-16)
godot2:tmp jdm$ rustc node.rs
godot2:tmp jdm$ ./node
48
I see that this is caused by https://github.com/rust-lang/rust/commit/57940d063c26ccabc7038f2fe9cf23faf9ee1ab6#diff-1ab410241f658d595f1c5eec7a979b01R409. Eight bytes for a bool is sad-making, since this increases the size of every single DOM node in Servo.
In #38368 I proposed packing this bit in RawTable::size or RawTable::capacity.
This is fairly crappy - an "insecure" HashMap is only 3 words long.
(Aligned up to) 4 words now, with the extra bool field added in #38368.
This is unrelated to the size cost of RandomState (16 bytes).
Wound something like this https://is.gd/pMbxfY work instead of the Unique<> we use in RawTable? Taking a bit from capacity or length could require some annoying changes to overflow handling, reserving, etc.
Edit: that would surely not please the borrow checker though. As Entry<,> require a mut ref to the table.
Edit2: nevermind that, we can access the &mut table using the readily available FullBucket and EmptyBucket.
Most helpful comment
I see that this is caused by https://github.com/rust-lang/rust/commit/57940d063c26ccabc7038f2fe9cf23faf9ee1ab6#diff-1ab410241f658d595f1c5eec7a979b01R409. Eight bytes for a bool is sad-making, since this increases the size of every single DOM node in Servo.