From 29189119a80c977acedea5b7b84f6768abce6428 Mon Sep 17 00:00:00 2001 From: Joshua Yanovski Date: Tue, 28 Jun 2022 19:53:08 -0700 Subject: [PATCH] Speed up chunk deserialization by another 80%. --- common/src/terrain/block.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/common/src/terrain/block.rs b/common/src/terrain/block.rs index 7e411ae77d..c821f0dd0d 100644 --- a/common/src/terrain/block.rs +++ b/common/src/terrain/block.rs @@ -531,19 +531,20 @@ impl<'a/*, Error: de::Error*/> TryFrom<&'a [u8]> for BlockVec { }); // Initially, the set bit list is empty. - let mut set_bits = bitarr![0; 256]; + let mut set_bits = /*bitarr!*/[false; 256]; // TODO: SIMD iteration. // NOTE: The block kind is guaranteed to be at the front, thanks to the repr(C). blocks.into_iter().for_each(|&[kind, _, _, _]| { - // TODO: Check assembly to see if the bounds check gets elided; if so, leave this as - // set instead of set_unchecked, to scope down the use of unsafe as much as possible. - set_bits.set(kind.into(), true); + // NOTE: Bounds check here appears to be either elided, or perfectly predicted, so we + // fortunately avoid using unsafe here. + /* set_bits.set(kind.into(), true); */ + set_bits[kind as usize] = true; }); // The invalid bits and the set bits should have no overlap. - set_bits &= invalid_bits; - if set_bits.any() { + invalid_bits &= set_bits; + if invalid_bits.any() { // At least one invalid bit was set, so there was an invalid BlockKind somewhere. // // TODO: Use radix representation of the bad block kind.