Skip to content

Conversation

@krakow10
Copy link

I've created a crate based on studying the design of ustr, with the goal of more explicit memory control. I'm looking to compare and contrast to ustr using these tests. I focused on simplicity, hashing at compile time, and the ergonomics of the local cache, specifically the fact that it can be dropped to reclaim the memory. This effortlessly enables multiple local caches like issue #30. The core idea is to omit the len field, use a DST, and pass around a fat pointer like &str. The types can be created at compile time, run time, interned into a cache, and created with the global cache. It also addresses #42 with UnhashedStr, another DST that is free to create from &str, using the trait bound Borrow<UnhashedStr> : &HashStr. The global cache is somewhat of an afterthought since it was the main thing that made me want to try my own implementation. I hope this is interesting because I sure had a great time making it.

The type signature of the main DST type is this:

pub struct HashStr{
	hash:u64,
	str:str,
}

Why

The reason I'm sharing is because I'm curious if any of the ideas I explored can benefit this library. You know, give and take since the IdentityHasher and Bins is shamelessly lifted directly from ustr :P

Benchmarks

I got pretty good results on these tests even though optimization was not a focus:

single raft ustr
time: [1.9225 ms 1.9266 ms 1.9335 ms]

single raft hash_str global interning
time: [2.3671 ms 2.3729 ms 2.3815 ms]

single raft hash_str local interning
time: [1.4005 ms 1.4019 ms 1.4033 ms]

single raft hash_str local interning with precomputed hashes
time: [743.77 µs 744.45 µs 745.31 µs]

@krakow10 krakow10 force-pushed the test-hash_str branch 2 times, most recently from d02a6e9 to 530af74 Compare April 26, 2025 23:17
@krakow10 krakow10 force-pushed the test-hash_str branch 2 times, most recently from 6d28611 to 66a8543 Compare May 1, 2025 19:29
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.

1 participant