Skip to content

Commit 84dff06

Browse files
committed
Cleanup after smallvec addition
1 parent fbed3c1 commit 84dff06

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
- Tree will now merge internal nodes when possible
1212
- Methods that access data have to be annotated with `#[require_deferred_drop]`
1313
- Introduced generic encoding for symbolic values `virolution::encoding::Symbol`
14+
- Use smallvec for storing mutations, this should reduce the number of unnecessary
15+
allocations especially when mutants go extinct right away
1416

1517
## 0.3.0 --- Mixed Performance (May 06, 2024)
1618

src/core/haplotype.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,14 @@ impl<S: Symbol> Wildtype<S> {
442442
pub fn new(sequence: Vec<S>) -> HaplotypeRef<S> {
443443
HaplotypeRef::new_cyclic(|reference| {
444444
Haplotype::Wildtype(Self {
445+
// head
445446
reference: reference.clone(),
446-
sequence: sequence.clone(),
447447
descendants: DescendantsCell::new(),
448+
449+
// body
450+
sequence: sequence.clone(),
451+
452+
// sync
448453
_dirty_descendants: AtomicIsize::new(0),
449454
})
450455
})
@@ -487,13 +492,18 @@ impl<S: Symbol> Mutant<S> {
487492
) -> HaplotypeRef<S> {
488493
HaplotypeRef::new_cyclic(|reference| {
489494
Haplotype::Mutant(Self {
495+
// head
490496
reference: reference.clone(),
491497
wildtype: wildtype.clone(),
492498
ancestor: ancestor.clone(),
499+
descendants: DescendantsCell::new(),
500+
501+
// body
493502
changes,
494503
generation,
495504
fitness: make_fitness_cache(),
496-
descendants: DescendantsCell::new(),
505+
506+
// sync
497507
_dirty_descendants: AtomicIsize::new(0),
498508
_defer_drop: Arc::new(Mutex::new(0)),
499509
_drop: Cell::new(None),
@@ -525,13 +535,18 @@ impl<S: Symbol> Mutant<S> {
525535

526536
// create new node
527537
let tmp_ref = HaplotypeRef::new(Haplotype::Mutant(Self {
538+
// head
528539
reference: last.reference.clone(),
529540
wildtype,
530541
ancestor,
542+
descendants: DescendantsCell::from_iter(descendants),
543+
544+
// body
531545
changes,
532546
generation,
533547
fitness: make_fitness_cache(),
534-
descendants: DescendantsCell::from_iter(descendants),
548+
549+
// sync
535550
_dirty_descendants: AtomicIsize::new(0),
536551
_defer_drop: last._defer_drop.clone(),
537552
_drop: Cell::new(None),
@@ -736,15 +751,20 @@ impl<S: Symbol> Recombinant<S> {
736751
) -> HaplotypeRef<S> {
737752
HaplotypeRef::new_cyclic(|reference| {
738753
Haplotype::Recombinant(Self {
754+
// head
739755
reference: reference.clone(),
740756
wildtype: wildtype.get_weak(),
741757
left_ancestor: left_ancestor.clone(),
742758
right_ancestor: right_ancestor.clone(),
759+
descendants: DescendantsCell::new(),
760+
761+
// body
743762
left_position,
744763
right_position,
745764
generation,
746765
fitness: make_fitness_cache(),
747-
descendants: DescendantsCell::new(),
766+
767+
// sync
748768
_dirty_descendants: AtomicIsize::new(0),
749769
})
750770
})

0 commit comments

Comments
 (0)