> Many operations involving two literals are optimized (to a certain level). So 
> it sort of surprises me that literal comparisons are not optimized and 
> literal contains only convert the right operand to a constant if possible. 
> I'd like to implement optimizations for these especially for the literal 
> contains. There is a TODO in the ast optimizer for literal comparisons as 
> well, and that's another reason I would like to have these added.

Though not having paid much attention to this over the years, I'm
pretty sure I've seen the topic float past from time-to-time. As I
recall, optimizing expressions involving two constants isn't a big win
in Python because that sort of expression occurs rarely in anything
other than test code. In C/C++ and its cousins, preprocessors
routinely expand names to constants, so

    2 == 2

might well be seen by the compiler even though the author actually wrote

  MUMBLE == FRAZZLE

If a Python programmer wrote such an expression, MUMBLE and FRAZZLE
would be names bound to a particular object, and could — theoretically
— be rebound at runtime, so such an expression couldn't safely be
optimized.

So, while you could optimize expressions involving just constants, the
benefit would be exceedingly small compared to the effort to write and
maintain the optimization code.

Skip
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/4TFW3Q2X42XKP4IK263ZXOGAZ3XXYUH4/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to