quick-cache icon indicating copy to clipboard operation
quick-cache copied to clipboard

Shouldn't Weighter::weight return u64?

Open vlovich opened this issue 10 months ago • 2 comments

It seems weird that the limit for a single item is limited to u32 even though weight for the overall collection is expressed as u64. Is that an intentional design choice to limit the weight for a given entry to 4 GiB?

vlovich avatar Apr 21 '24 21:04 vlovich

That was intentional in order to avoid dealing with the possibility of overflow.

I think overflows could be revisited if it's not too annoying to handle or even have the internal weight tracking be u128.

arthurprs avatar Apr 22 '24 07:04 arthurprs

I see. Wouldn't overflows just be a checked_sub/checked_add if you want to enforce panic (slightly slower in optimized builds) or just normal math & leave it to be the users problem (i.e. panic in debug, but "bad things happen" in release)?

vlovich avatar Apr 22 '24 17:04 vlovich