python / python/cpython

Use interned versions of string constants if they're already present

Open
#140,328 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

easy interpreter-core performance type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

Proposal:

For now intern_constants function in Objects/codeobject.c uses should_intern_string to check if that string should be interned. And do nothing if should_intern_string returned 0. Maybe it'll be better to check if this string already have interned variant and use it if present? Because there's no need to keep equal strings in memory. The small downside is some time needed for this checking.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-140688

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Objects/codeobject.c at intern_constants and trace how should_intern_string currently determines whether strings are interned. Review linked PR gh-140688 before starting, and consider the work complete when existing interned equivalents are reused without retaining duplicate equal strings.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
backend, performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.