On Thu, 24 Nov 2022 at 06:46, Barry Scott <[email protected]> wrote:
> I have written a lot of low level protocol and IOCTL calls that cannot think
> of a time this would have helped me.
> struct is often a mean to create blocks of binary data.
>
> Long strings of binary data would be a maintenance issue. What do all the
> bits mean?
Sounds like a system of compile-time evaluation - as a way to extend
constant folding to more forms - might be the way to do this, then. I
don't think the compiler can optimize this:
x = bytes.fromhex("0123456789abcdef")
and while it's theoretically possible to optimize this, it falls down
badly on the "why was this written like this?" test:
x = b"".fromhex("0123456789abcdef")
But suppose there were some way to say "this is intended to be a
compile-time constant, please evaluate it and retain the result as a
literal". Obviously this is only valid if the result is a type that
can be saved, but it would allow some quite nice optimizations that
might even include struct calls.
On the flip side, the performance gain probably wouldn't be all that
much compared to doing the work at import time. For literals used in
tight loops, there'd still be SOME benefit (if the work is done at
import time, it would have to be stored as a global, and that means
the inner loop is looking up a global rather than loading a constant),
but it would have to be a fairly hot piece of code to be worth the
effort.
ChrisA
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/RLW7D73GCDGFCL4UQXNOI2MAK7AWQ6QQ/
Code of Conduct: http://python.org/psf/codeofconduct/