This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients benjamin.peterson, brett.cannon, ncoghlan, serhiy.storchaka, yselivanov
Date 2018-04-17.16:21:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1523982101.74.0.682650639539.issue33298@psf.upfronthosting.co.za>
In-reply-to
Content
Currently every constant is wrapped with _PyCode_ConstantKey() in the compiler. This is necessary for distinguishing numbers 1, 1.0 and 1.0+0j, 0.0 and -0.0, and avoiding warnings from comparing string and bytes constants.

But the change that introduced using _PyCode_ConstantKey() for constants (in issue25843) also caused to wrapping names with _PyCode_ConstantKey(). This is superfluous because all names are strings. This just consumes memory for 2-tuples for every name and spends CPU time for creating these tuples for every name.

There are two ways of getting rid of this overhead.

1. Make _PyCode_ConstantKey() returning just a string itself for string argument. Strings are never equal to tuples. This requires minimal changes.

2. Use different helpers for adding constants and names, and use _PyCode_ConstantKey() only for names. This will clean up the code for names, but needs adding few special functions and macros.

I'm going to apply both solution. The first one will add a benefit for string constants (and other common types), the second one will help moving the folding tuples of constants from peephole.c to compile.c and generalizing it for lists, sets and dicts of constants, constant default values, constant arguments, etc.

The following PR implements the second option.
History
Date User Action Args
2018-04-17 16:21:41serhiy.storchakasetrecipients: + serhiy.storchaka, brett.cannon, ncoghlan, benjamin.peterson, yselivanov
2018-04-17 16:21:41serhiy.storchakasetmessageid: <1523982101.74.0.682650639539.issue33298@psf.upfronthosting.co.za>
2018-04-17 16:21:41serhiy.storchakalinkissue33298 messages
2018-04-17 16:21:41serhiy.storchakacreate