bodoni / svg

Composer and parser for SVG
Other
304 stars 44 forks source link

Allow for custom storage of `Attributes` #69

Open tgross35 opened 1 year ago

tgross35 commented 1 year ago

It seems like internally, Attributes is a std::collections::HashMap. Would it be possible to use hashbrown::HashMap? Probably behind a Cargo flag to make hashbrown an optional dependency.

Reasoning: the HashMap in collections is extremely collision resistant (SipHash), but this means it is slower and has a larger per-entry memory overhead than alternatives. hashbrown uses ahash which is much faster and has a smaller per-entry overhead (1/8 the size if I recall correctly). ahash is not as collision resistant, but this is highly unlikely to be exploitable for this use case.

All the functions taking DefaultHasher would need to become generic.

Alternatively, using ahash directly without going through hashbrown would provide the same results.

IvanUkhov commented 1 year ago

Thank you for the issue! In general, this crate strives to be minimalistic and independent, and adding dependencies would go against this philosophy. However, it would be appropriate to abstract away which struct is used for storing attributes via a trait so that one can implement that trait for anything else elsewhere.