From 2d942bbfc986a7eff6e09a0d8b1c3b5fb5d9c644 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 1 Apr 2021 10:03:48 +0200 Subject: [PATCH] Box up the BitVec array The `Search::best` field will take about 8000 bytes. In some of our usage with rayon, this appeared to cause stack overflows. Boxing it up makes the code slower by about 1-2%, but should hopefully avoid stack overflows. --- instant-segment/Cargo.toml | 2 +- instant-segment/src/lib.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/instant-segment/Cargo.toml b/instant-segment/Cargo.toml index 01c93c6..495301f 100644 --- a/instant-segment/Cargo.toml +++ b/instant-segment/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "instant-segment" -version = "0.7.2" +version = "0.8.0" authors = ["Dirkjan Ochtman "] edition = "2018" license = "Apache-2.0" diff --git a/instant-segment/src/lib.rs b/instant-segment/src/lib.rs index d929a47..658141f 100644 --- a/instant-segment/src/lib.rs +++ b/instant-segment/src/lib.rs @@ -177,7 +177,7 @@ impl<'a> SegmentState<'a> { #[derive(Clone)] pub struct Search { memo: HashMap<(u8, u8, u8), (f64, BitVec)>, - best: [BitVec; SEGMENT_SIZE], + best: Box<[BitVec; SEGMENT_SIZE]>, result: Vec, } @@ -200,7 +200,7 @@ impl Default for Search { fn default() -> Self { Self { memo: HashMap::default(), - best: [BitVec::default(); SEGMENT_SIZE], + best: Box::new([BitVec::default(); SEGMENT_SIZE]), result: Vec::new(), } }