@@ -166,11 +166,11 @@ fn random_string(rng: &mut StdRng, len: usize) -> String {
166166fn strings_with_shared_prefix (
167167 rng : & mut StdRng ,
168168 count : usize ,
169- prefix_len : usize ,
169+ prefix : & str ,
170+ discriminator : char ,
170171) -> Vec < String > {
171- let prefix = random_string ( rng, prefix_len) ;
172172 ( 0 ..count)
173- . map ( |_| format ! ( "{}{}" , prefix , random_string( rng, 8 ) ) ) // prefix + random 8-char suffix
173+ . map ( |_| format ! ( "{prefix }{}{discriminator} " , random_string( rng, 7 ) ) )
174174 . collect ( )
175175}
176176
@@ -275,12 +275,14 @@ fn bench_string_shared_prefix<A>(
275275 . wrapping_add ( prefix_len as u64 * 0x4444 ) ;
276276 let mut rng = StdRng :: seed_from_u64 ( seed) ;
277277
278- // Generate IN list with a shared prefix.
279- let haystack = strings_with_shared_prefix ( & mut rng, list_size, prefix_len) ;
278+ // Use the same prefix and equal-length, disjoint suffixes for both pools so
279+ // misses exercise length/prefix collisions rather than immediate rejection.
280+ let prefix = random_string ( & mut rng, prefix_len) ;
281+ let haystack = strings_with_shared_prefix ( & mut rng, list_size, & prefix, 'h' ) ;
280282
281283 // Generate non-matching strings with the same prefix to keep misses close
282284 // to the matching set.
283- let non_match_pool = strings_with_shared_prefix ( & mut rng, 100 , prefix_len ) ;
285+ let non_match_pool = strings_with_shared_prefix ( & mut rng, 100 , & prefix , 'm' ) ;
284286
285287 // Generate array with controlled match rate
286288 let values: A = ( 0 ..ARRAY_SIZE )
@@ -313,19 +315,29 @@ fn bench_string_mixed_lengths<A>(
313315 name : & str ,
314316 list_size : usize ,
315317 match_rate : f64 ,
318+ inline_rate : f64 ,
316319 to_scalar : fn ( String ) -> ScalarValue ,
317320) where
318321 A : Array + FromIterator < Option < String > > + ' static ,
319322{
320323 let seed = 0xABCD_EF01_u64 . wrapping_add ( list_size as u64 * 0x5555 ) ;
321324 let mut rng = StdRng :: seed_from_u64 ( seed) ;
322325
323- // Mixed lengths: some short (<= 12), some long (> 12)
324- let lengths = [ 4 , 8 , 12 , 16 , 20 , 24 ] ;
326+ let inline_lengths = [ 4 , 8 , 12 ] ;
327+ let long_lengths = [ 16 , 20 , 24 ] ;
328+ let inline_count = ( ( list_size as f64 * inline_rate) . round ( ) as usize )
329+ . max ( 1 )
330+ . min ( list_size - 1 ) ;
325331
326332 // Generate IN list with mixed lengths
327333 let haystack: Vec < String > = ( 0 ..list_size)
328- . map ( |_| {
334+ . map ( |idx| {
335+ let inline = idx < inline_count;
336+ let lengths = if inline {
337+ & inline_lengths
338+ } else {
339+ & long_lengths
340+ } ;
329341 let len = * lengths. choose ( & mut rng) . unwrap ( ) ;
330342 random_string ( & mut rng, len)
331343 } )
@@ -337,6 +349,11 @@ fn bench_string_mixed_lengths<A>(
337349 Some ( if !haystack. is_empty ( ) && rng. random_bool ( match_rate) {
338350 haystack. choose ( & mut rng) . unwrap ( ) . clone ( )
339351 } else {
352+ let lengths = if rng. random_bool ( inline_rate) {
353+ & inline_lengths
354+ } else {
355+ & long_lengths
356+ } ;
340357 let len = * lengths. choose ( & mut rng) . unwrap ( ) ;
341358 random_string ( & mut rng, len)
342359 } )
@@ -602,6 +619,7 @@ fn bench_utf8(c: &mut Criterion) {
602619 & format ! ( "mixed_len/list={list_size}/match={match_pct}%" ) ,
603620 list_size,
604621 match_pct as f64 / 100.0 ,
622+ 0.5 ,
605623 to_scalar,
606624 ) ;
607625 }
@@ -694,6 +712,23 @@ fn bench_utf8view(c: &mut Criterion) {
694712 & format ! ( "mixed_len/list={list_size}/match={match_pct}%" ) ,
695713 list_size,
696714 match_pct as f64 / 100.0 ,
715+ 0.5 ,
716+ to_scalar,
717+ ) ;
718+ }
719+ }
720+
721+ // Strongly skewed mixed lists exercise routing near the all-inline and
722+ // all-long boundaries while retaining both representations.
723+ for inline_pct in [ 2 , 98 ] {
724+ for match_pct in MATCH_RATES {
725+ bench_string_mixed_lengths :: < StringViewArray > (
726+ c,
727+ "utf8view" ,
728+ & format ! ( "mixed_len/inline={inline_pct}%/list=64/match={match_pct}%" ) ,
729+ 64 ,
730+ match_pct as f64 / 100.0 ,
731+ inline_pct as f64 / 100.0 ,
697732 to_scalar,
698733 ) ;
699734 }
0 commit comments