Repository: vercel/next.js
File: turbopack/crates/turbo-persistence/src/db.rs (Rust)

Code before:
                    let used_key_hashes: Option<qfilter::Filter> = {
                        let filters: Vec<qfilter::Filter> = meta_files
                            .iter()
                            .filter(|m| m.family() == family)
                            .filter_map(|meta_file| {
                                meta_file.deserialize_used_key_hashes_amqf().transpose()
                            })
                            .collect::<Result<Vec<_>>>()?
                            .into_iter()
                            .filter(|amqf| !amqf.is_empty())
                            .collect();
                        let total_len: u64 = filters.iter().map(|f| f.len()).sum();
                        if total_len == 0 {
                            None
                        } else {
                            let mut merged =
                                qfilter::Filter::with_fingerprint_size(total_len, u64::BITS as u8)
                                    .expect("Failed to create merged AMQF filter");
                            for filter in &filters {
                                merged
                                    .merge(false, filter)
                                    .expect("Failed to merge AMQF filters");
                            }
                            merged.shrink_to_fit();
                            Some(merged)
                        }
                    };

                    // Later we will remove the merged files
                    let sst_seq_numbers_to_delete = merge_jobs
                        .iter()
                        .filter(|l| l.len() > 1)
                        .flat_map(|l| l.iter().copied())
                        .map(|index| ssts_with_ranges[index].seq)
                        .collect::<Vec<_>>();

                    // Merge SST files
                    let span = tracing::trace_span!("merge files");
                    enum PartialMergeResult<'l> {
                        Merged {
                            new_sst_files: Vec<(u32, File, StaticSortedFileBuilderMeta<'static>)>,
                            blob_seq_numbers_to_delete: Vec<u32>,
                            keys_written: u64,
                            indicies: SmallVec<[usize; 1]>,
                        },
                        Move {
                            seq: u32,
                            meta: StaticSortedFileBuilderMeta<'l>,
                        },
                    }
                    let merge_result = self

Review comment (suggestion):
There could be an optimization here when there is only a single filter (`filters.len() == 1`)

Code after:
                    let used_key_hashes: Option<qfilter::Filter> = {
                        let filters: Vec<qfilter::Filter> = meta_files
                            .iter()
                            .filter(|m| m.family() == family)
                            .filter_map(|meta_file| {
                                meta_file.deserialize_used_key_hashes_amqf().transpose()
                            })
                            .collect::<Result<Vec<_>>>()?
                            .into_iter()
                            .filter(|amqf| !amqf.is_empty())
                            .collect();
                        if filters.is_empty() {
                            None
                        } else if filters.len() == 1 {
                            // Just directly use the single item
                            filters.into_iter().next()
                        } else {
                            let total_len: u64 = filters.iter().map(|f| f.len()).sum();
                            let mut merged =
                                qfilter::Filter::with_fingerprint_size(total_len, u64::BITS as u8)
                                    .expect("Failed to create merged AMQF filter");
                            for filter in &filters {
                                merged
                                    .merge(false, filter)
                                    .expect("Failed to merge AMQF filters");
                            }
                            merged.shrink_to_fit();
                            Some(merged)
                        }
                    };

                    // Later we will remove the merged files
                    let sst_seq_numbers_to_delete = merge_jobs
                        .iter()
                        .filter(|l| l.len() > 1)
                        .flat_map(|l| l.iter().copied())
                        .map(|index| ssts_with_ranges[index].seq)
                        .collect::<Vec<_>>();

                    // Merge SST files
                    let span = tracing::trace_span!("merge files");
                    enum PartialMergeResult<'l> {
                        Merged {
                            new_sst_files: Vec<(u32, File, StaticSortedFileBuilderMeta<'static>)>,
                            blob_seq_numbers_to_delete: Vec<u32>,
                            keys_written: u64,
                            indicies: SmallVec<[usize; 1]>,
                        },
                        Move {
                            seq: u32,
                            meta: StaticSortedFileBuilderMeta<'l>,