You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from #7, we bounds check twice in Pread, once in the TryFromCtx, and again in FromCtx (technically, it's everytime we access the byte array).
Consequently, there's room for some optimization here.
To be clear:
I'm definitely for optimization at this point, as the crate is becoming mature and I'd like to hit 1.0 soon, and well optimized numeric readers would be great
I'd like to see some basic benchmarks as to whether these bounds checks are actually worth optimizing.
It might be better to clean up TryFromCtx (break backwards compat, since we're below 1.0), remove offset logic from the trait, and move into Pread itself, and make fully generic with Index trait bounds, and reduce it to the bounds check + assert, which we might be ok to live with, again, needs measuring.
Anyway, as @goandylok suggests, some possible avenues:
Mark FromCtx and cread‘s members unsafe to give away the responsibility of bound check to call site.
Make FromCtx to be a wrapper of TryFromCtx by calling expect() on TryFromCtx's result.
Honestly, 1. is a "nuclear option" for me; I'm really hesitant to mark it unsafe, and would really require evidence (specifically benchmarks) to do so. Once it's unsafe, it's hard to put that genie back in the bottle; history has shown people are very unlikely to check bounds, even when its in their best interest, so this is definitely going to require some serious consideration. I might even prefer a UnsafeFromCtx, and have this isolated to just the Cread trait, but that might be too much.
I also don't like the divergence from the std trait; why is FromCtx unsafe? It just shouldn't fail, similar to From trait in std, which isn't unsafe.
Anyway, those are some thoughts.
The text was updated successfully, but these errors were encountered:
from #7, we bounds check twice in
Pread
, once in theTryFromCtx
, and again inFromCtx
(technically, it's everytime we access the byte array).Consequently, there's room for some optimization here.
To be clear:
TryFromCtx
(break backwards compat, since we're below 1.0), remove offset logic from the trait, and move intoPread
itself, and make fully generic with Index trait bounds, and reduce it to the bounds check + assert, which we might be ok to live with, again, needs measuring.Anyway, as @goandylok suggests, some possible avenues:
Honestly, 1. is a "nuclear option" for me; I'm really hesitant to mark it unsafe, and would really require evidence (specifically benchmarks) to do so. Once it's unsafe, it's hard to put that genie back in the bottle; history has shown people are very unlikely to check bounds, even when its in their best interest, so this is definitely going to require some serious consideration. I might even prefer a UnsafeFromCtx, and have this isolated to just the
Cread
trait, but that might be too much.I also don't like the divergence from the std trait; why is
FromCtx
unsafe? It just shouldn't fail, similar toFrom
trait in std, which isn't unsafe.Anyway, those are some thoughts.
The text was updated successfully, but these errors were encountered: