byte_type icon indicating copy to clipboard operation
byte_type copied to clipboard

`rangeCheck` internal method is slow

Open MierenManz opened this issue 1 year ago • 1 comments

Currently super.rangeCheck is used a lot in the code to throw RangeError before writing into a buffer whenever a bound will be crossed (in comparison without this check we may have partial writes meaning that the buffer may contain invalid data). This "correctness" comes with a small performance penalty for each class that inherits SizedType. For single types the penalty is not much but for compound types like arrays, tuples and struct it can become quite a hassle.

With rangecheck image Without rangecheck image

I think it may be a good idea to either remove the rangecheck entirely and just declare the written buffer as not good to read from.

Alternatively we can remove a bit of the penalty in compound types and only let the top level type do the range check (all types under the top level will do a bound check that is less than the total size of it's parent)

Some data: Time penalty is anywhere from 37% (cold start) to 12% (avg)

MierenManz avatar Jul 17 '24 21:07 MierenManz