New submission from Serhiy Storchaka <storchaka+cpyt...@gmail.com>:

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.

----------
assignee: serhiy.storchaka
components: Interpreter Core
messages: 315405
nosy: benjamin.peterson, brett.cannon, ncoghlan, serhiy.storchaka, yselivanov
priority: normal
severity: normal
status: open
title: Wrap only constants with _PyCode_ConstantKey() in the compiler.
type: performance
versions: Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue33298>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to