classification
Title: Wrap only constants with _PyCode_ConstantKey() in the compiler.
Type: performance Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: benjamin.peterson, brett.cannon, methane, ncoghlan, serhiy.storchaka, vstinner, yselivanov
Priority: normal Keywords: patch

Created on 2018-04-17 16:21 by serhiy.storchaka, last changed 2018-04-20 13:08 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 6512 merged serhiy.storchaka, 2018-04-17 16:26
Messages (3)
msg315405 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-04-17 16:21
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.
msg315408 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-04-17 16:57
See issue33299 for the first option.
msg315509 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-04-20 13:01
New changeset d70c2a6894d80410b6f5a3129d6b1062ea8fd4e4 by Serhiy Storchaka in branch 'master':
bpo-33298: Wrap only constants with _PyCode_ConstantKey() in the compiler. (GH-6512)
https://github.com/python/cpython/commit/d70c2a6894d80410b6f5a3129d6b1062ea8fd4e4
History
Date User Action Args
2018-04-20 13:08:41serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-04-20 13:01:28serhiy.storchakasetmessages: + msg315509
2018-04-18 12:53:55methanesetnosy: + methane
2018-04-17 16:57:34serhiy.storchakasetmessages: + msg315408
2018-04-17 16:30:16serhiy.storchakasetnosy: + vstinner
2018-04-17 16:26:03serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request6205
2018-04-17 16:21:41serhiy.storchakacreate