@@ -9,39 +9,33 @@ use crate::{symbol::expect_valid_symbol, DefaultSymbol, Symbol};
9
9
use alloc:: { string:: String , vec:: Vec } ;
10
10
use core:: { iter:: Enumerate , marker:: PhantomData , slice} ;
11
11
12
- /// An interner backend that reduces memory allocations by using string buckets.
13
- ///
14
- /// # Note
15
- ///
16
- /// Implementation inspired by matklad's blog post that can be found here:
17
- /// <https://matklad.github.io/2020/03/22/fast-simple-rust-interner.html>
18
- ///
19
- /// # Usage Hint
20
- ///
21
- /// Use when deallocations or copy overhead is costly or when
22
- /// interning of static strings is especially common.
23
- ///
24
- /// # Usage
25
- ///
26
- /// - **Fill:** Efficiency of filling an empty string interner.
27
- /// - **Resolve:** Efficiency of interned string look-up given a symbol.
28
- /// - **Allocations:** The number of allocations performed by the backend.
29
- /// - **Footprint:** The total heap memory consumed by the backend.
30
- /// - **Contiguous:** True if the returned symbols have contiguous values.
31
- /// - **Iteration:** Efficiency of iterating over the interned strings.
32
- ///
33
- /// Rating varies between **bad**, **ok**, **good** and **best**.
34
- ///
35
- /// | Scenario | Rating |
36
- /// |:------------|:--------:|
37
- /// | Fill | **good** |
38
- /// | Resolve | **best** |
39
- /// | Allocations | **good** |
40
- /// | Footprint | **ok** |
41
- /// | Supports `get_or_intern_static` | **yes** |
42
- /// | `Send` + `Sync` | **yes** |
43
- /// | Contiguous | **yes** |
44
- /// | Iteration | **best** |
12
+ /// An interner backend that reduces memory allocations by using buckets.
13
+ ///
14
+ /// # Overview
15
+ /// This interner uses fixed-size buckets to store interned strings. Each bucket is
16
+ /// allocated once and holds a set number of strings. When a bucket becomes full, a new
17
+ /// bucket is allocated to hold more strings. Buckets are never deallocated, which reduces
18
+ /// the overhead of frequent memory allocations and copying.
19
+ ///
20
+ /// ## Trade-offs
21
+ /// - **Advantages:**
22
+ /// - Strings in already used buckets remain valid and accessible even as new strings
23
+ /// are added.
24
+ /// - **Disadvantages:**
25
+ /// - Slightly slower access times due to double indirection (looking up the string
26
+ /// involves an extra level of lookup through the bucket).
27
+ /// - Memory may be used inefficiently if many buckets are allocated but only partially
28
+ /// filled because of large strings.
29
+ ///
30
+ /// ## Use Cases
31
+ /// This backend is ideal when interned strings must remain valid even after new ones are
32
+ /// added.general use
33
+ ///
34
+ /// Refer to the [comparison table][crate::_docs::comparison_table] for comparison with
35
+ /// other backends.
36
+ ///
37
+ /// [matklad's blog post]:
38
+ /// https://matklad.github.io/2020/03/22/fast-simple-rust-interner.html
45
39
#[ derive( Debug ) ]
46
40
pub struct BucketBackend < ' i , S : Symbol = DefaultSymbol > {
47
41
spans : Vec < InternedStr > ,
0 commit comments