@@ -24,7 +24,7 @@ use mz_ore::task::spawn;
2424use mz_persist:: location:: Blob ;
2525use mz_persist_types:: codec_impls:: VecU8Schema ;
2626use mz_persist_types:: { Codec , Codec64 } ;
27- use timely:: progress:: Timestamp ;
27+ use timely:: progress:: { Antichain , Timestamp } ;
2828use timely:: PartialOrder ;
2929use tokio:: sync:: mpsc:: Sender ;
3030use tokio:: sync:: { mpsc, oneshot, TryAcquireError } ;
@@ -410,6 +410,31 @@ where
410410 schemas : Schemas < K , V > ,
411411 ) -> Result < CompactRes < T > , anyhow:: Error > {
412412 let ( ) = Self :: validate_req ( & req) ?;
413+
414+ // We introduced a fast-path optimization in https://github.com/MaterializeInc/materialize/pull/15363
415+ // but had to revert it due to a very scary bug. Here we count how many of our compaction reqs
416+ // could be eligible for the optimization to better understand whether it's worth trying to
417+ // reintroduce it.
418+ let mut single_nonempty_batch = None ;
419+ for batch in & req. inputs {
420+ if batch. len > 0 {
421+ match single_nonempty_batch {
422+ None => single_nonempty_batch = Some ( batch) ,
423+ Some ( _previous_nonempty_batch) => {
424+ single_nonempty_batch = None ;
425+ break ;
426+ }
427+ }
428+ }
429+ }
430+ if let Some ( single_nonempty_batch) = single_nonempty_batch {
431+ if single_nonempty_batch. runs . len ( ) == 0
432+ && single_nonempty_batch. desc . since ( ) != & Antichain :: from_elem ( T :: minimum ( ) )
433+ {
434+ metrics. compaction . fast_path_eligible . inc ( ) ;
435+ }
436+ }
437+
413438 // compaction needs memory enough for at least 2 runs and 2 in-progress parts
414439 assert ! ( cfg. compaction_memory_bound_bytes >= 4 * cfg. batch. blob_target_size) ;
415440 // reserve space for the in-progress part to be held in-mem representation and columnar
0 commit comments