@@ -91,12 +91,12 @@ struct TtlExactStorage {
9191}
9292
9393impl TtlExactStorage {
94- fn new ( value_limit : usize , ttl : Duration , generations : u8 ) -> Self {
94+ fn new ( ttl : Duration , generations : u8 ) -> Self {
9595 let now = Instant :: now ( ) ;
9696 let divisor = generations. max ( 1 ) as u32 ;
9797 let sweep_interval = ( ttl / divisor) . max ( Duration :: from_secs ( 1 ) ) ;
9898 Self {
99- map : HashMap :: with_capacity ( value_limit ) ,
99+ map : HashMap :: new ( ) ,
100100 ttl,
101101 sweep_interval,
102102 last_sweep : now,
@@ -284,23 +284,20 @@ impl fmt::Debug for TagValueSetStorage {
284284}
285285
286286impl AcceptedTagValueSet {
287- /// Construct the appropriate backend.
287+ /// Construct the appropriate backend from `(mode, ttl_secs, ttl_generations)` .
288288 ///
289- /// When `ttl_secs` is `None` (default), the backend is identical to the pre-TTL
290- /// behavior — `HashSet` for exact, single `BloomFilter` for probabilistic — so
291- /// existing configs see zero behavioral change.
292- pub fn new (
293- value_limit : usize ,
294- mode : & Mode ,
295- ttl_secs : Option < u64 > ,
296- ttl_generations : u8 ,
297- ) -> Self {
289+ /// When `ttl_secs` is `None` or `0`, this is identical to the pre-TTL
290+ /// behavior — `HashSet` for exact, single `BloomFilter` for probabilistic —
291+ /// so existing configs see zero behavioral change. Neither backend
292+ /// pre-allocates with `value_limit` capacity (see vectordotdev/vector#25480
293+ /// for the memory rationale).
294+ pub fn new ( mode : & Mode , ttl_secs : Option < u64 > , ttl_generations : u8 ) -> Self {
298295 let ttl = ttl_secs. and_then ( |s| ( s > 0 ) . then ( || Duration :: from_secs ( s) ) ) ;
299296
300297 let storage = match ( mode, ttl) {
301- ( Mode :: Exact , None ) => TagValueSetStorage :: Set ( HashSet :: with_capacity ( value_limit ) ) ,
298+ ( Mode :: Exact , None ) => TagValueSetStorage :: Set ( HashSet :: new ( ) ) ,
302299 ( Mode :: Exact , Some ( ttl) ) => {
303- TagValueSetStorage :: TtlSet ( TtlExactStorage :: new ( value_limit , ttl, ttl_generations) )
300+ TagValueSetStorage :: TtlSet ( TtlExactStorage :: new ( ttl, ttl_generations) )
304301 }
305302 ( Mode :: Probabilistic ( config) , None ) => {
306303 TagValueSetStorage :: Bloom ( BloomFilterStorage :: new ( config. cache_size_per_key ) )
@@ -392,7 +389,7 @@ mod tests {
392389
393390 #[ test]
394391 fn exact_no_ttl_preserves_today_behavior ( ) {
395- let mut set = AcceptedTagValueSet :: new ( 2 , & Mode :: Exact , None , 4 ) ;
392+ let mut set = AcceptedTagValueSet :: new ( & Mode :: Exact , None , 4 ) ;
396393 assert ! ( !set. contains( & v( "a" ) ) ) ;
397394 assert_eq ! ( set. len( ) , 0 ) ;
398395 set. insert ( v ( "a" ) ) ;
@@ -407,7 +404,7 @@ mod tests {
407404 let mode = Mode :: Probabilistic ( BloomFilterConfig {
408405 cache_size_per_key : default_cache_size ( ) ,
409406 } ) ;
410- let mut set = AcceptedTagValueSet :: new ( 2 , & mode, None , 4 ) ;
407+ let mut set = AcceptedTagValueSet :: new ( & mode, None , 4 ) ;
411408 set. insert ( v ( "a" ) ) ;
412409 set. insert ( v ( "a" ) ) ;
413410 assert_eq ! ( set. len( ) , 1 , "duplicate insert must not bump count" ) ;
@@ -426,7 +423,7 @@ mod tests {
426423 #[ test]
427424 fn ttl_exact_expires_values_past_ttl ( ) {
428425 let ttl = Duration :: from_secs ( 60 ) ;
429- let mut s = TtlExactStorage :: new ( 8 , ttl, 4 ) ;
426+ let mut s = TtlExactStorage :: new ( ttl, 4 ) ;
430427 // t0: insert v=a manually so we control its timestamp.
431428 let t0 = Instant :: now ( ) ;
432429 s. map . insert ( v ( "a" ) , t0) ;
@@ -446,7 +443,7 @@ mod tests {
446443 // forward — otherwise sweeps continue to use the old (potentially
447444 // expired) timestamp. A short sleep guarantees `Instant::now()` is
448445 // strictly after `t_insert` on every platform.
449- let mut s = TtlExactStorage :: new ( 8 , Duration :: from_secs ( 60 ) , 4 ) ;
446+ let mut s = TtlExactStorage :: new ( Duration :: from_secs ( 60 ) , 4 ) ;
450447 let t_insert = Instant :: now ( ) ;
451448 s. map . insert ( v ( "a" ) , t_insert) ;
452449 s. last_sweep = t_insert;
@@ -465,7 +462,7 @@ mod tests {
465462 fn ttl_exact_sweep_interval_floors_to_one_second ( ) {
466463 // ttl=2s, generations=8 → naive slice = 250ms; we floor to 1s so sweeps
467464 // never become dominant. Verify the floor.
468- let s = TtlExactStorage :: new ( 8 , Duration :: from_secs ( 2 ) , 8 ) ;
465+ let s = TtlExactStorage :: new ( Duration :: from_secs ( 2 ) , 8 ) ;
469466 assert ! ( s. sweep_interval >= Duration :: from_secs( 1 ) ) ;
470467 }
471468
@@ -474,7 +471,7 @@ mod tests {
474471 // Regression for the `DropEvent` pre-check bug: a read-only check
475472 // must NOT update the stored Instant.
476473 let ttl = Duration :: from_secs ( 60 ) ;
477- let mut s = TtlExactStorage :: new ( 8 , ttl, 4 ) ;
474+ let mut s = TtlExactStorage :: new ( ttl, 4 ) ;
478475 let t0 = Instant :: now ( ) ;
479476 s. map . insert ( v ( "a" ) , t0) ;
480477 s. last_sweep = t0;
0 commit comments