diff --git a/pumpkin-crates/core/src/engine/constraint_satisfaction_solver.rs b/pumpkin-crates/core/src/engine/constraint_satisfaction_solver.rs index 4e48687d1..08b3d031c 100644 --- a/pumpkin-crates/core/src/engine/constraint_satisfaction_solver.rs +++ b/pumpkin-crates/core/src/engine/constraint_satisfaction_solver.rs @@ -172,7 +172,7 @@ impl Default for SatisfactionSolverOptions { random_generator: SmallRng::seed_from_u64(42), proof_log: ProofLog::default(), learning_options: LearningOptions::default(), - memory_preallocated: 1000, + memory_preallocated: 50, } } } diff --git a/pumpkin-crates/core/src/propagators/nogoods/arena_allocator.rs b/pumpkin-crates/core/src/propagators/nogoods/arena_allocator.rs index 2fb6d3d4b..d8e6c7b29 100644 --- a/pumpkin-crates/core/src/propagators/nogoods/arena_allocator.rs +++ b/pumpkin-crates/core/src/propagators/nogoods/arena_allocator.rs @@ -27,6 +27,12 @@ pub(crate) struct ArenaAllocator { /// The current index for the next [`NogoodId`] which is entered; see /// [`ArenaAllocator::nogood_id_to_index`]. current_index: u32, + /// The number of elements (i.e., [`PredicateId`]s), that are created when the arena is + /// initialised. + /// + /// Note that it is lazily initialised, so that this memory is only allocated the first time + /// that a nogood is added to the arena. + initial_capacity: usize, } #[derive(Clone, Copy, Debug, Hash)] @@ -45,15 +51,20 @@ impl StorageKey for NogoodIndex { impl ArenaAllocator { pub(crate) fn new(capacity: usize) -> Self { Self { - nogoods: Vec::with_capacity(capacity), + nogoods: Vec::default(), nogood_id_to_index: HashMap::default(), current_index: 0, + initial_capacity: capacity, } } /// Inserts the nogood consisting of [`PredicateId`]s and returns its corresponding /// [`NogoodId`]. pub(crate) fn insert(&mut self, nogood: Vec) -> NogoodId { + if self.nogoods.is_empty() { + self.nogoods.reserve_exact(self.initial_capacity); + } + let nogood_id = NogoodId::create_from_index(self.nogoods.len()); // We store the NogoodId with its index. diff --git a/pumpkin-solver/src/bin/pumpkin-solver/main.rs b/pumpkin-solver/src/bin/pumpkin-solver/main.rs index 4d53c8fee..1edc75199 100644 --- a/pumpkin-solver/src/bin/pumpkin-solver/main.rs +++ b/pumpkin-solver/src/bin/pumpkin-solver/main.rs @@ -399,7 +399,7 @@ struct Args { optimisation_strategy: OptimisationStrategy, /// The amount of memory (in MB) that is preallocated for storing nogoods. - #[arg(long = "memory-preallocated", default_value_t = 1000)] + #[arg(long = "memory-preallocated", default_value_t = 50)] memory_preallocated: usize, }