interned-string
This crate exposes IString, an immutable and interned string type.
It's built for high performance and with multithreading in mind.
Reading an IString's contents is very fast, lock free and wait free (thanks to left_right).
The IString can be shared and read from any number of threads.
It scales linearly with the number of reading threads.
The tradeoff is that creating a new IString is slower.
A radix tree (compact trie) needs to be traversed to deduplicate the new string,
a lock needs to be acquired, and the tree needs to be updated in case the string wasn't interned yet.
While the tree walk can be done in parallel from multiple threads, the lock prevents linear scaling for writes.
Getting Started
You can intern any String or &str value by calling intern().
You can pass an IString by reference to any function that accepts a &str.
use Intern;
If you enable the serde feature, you can use IString in place of String in your DTOs.
[]
= { = "1.0", = ["derive"] }
= "1.0"
= { = "0.1", = ["serde"] }
use Deserialize;
use IString;
Contributing
Feel free to open a PR. Any contribution is greatly appreciated.
If you have a suggestion, please open an Issue.
License
Acknowledgments
Special thanks to Jon Gjengset (@jonhoo) for providing the inspiration for this crate, and for his work on left-right.