Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fewer statics in Argument Clinic. #82322

Closed
ericsnowcurrently opened this issue Sep 12, 2019 · 6 comments
Closed

Use fewer statics in Argument Clinic. #82322

ericsnowcurrently opened this issue Sep 12, 2019 · 6 comments
Assignees
Labels
3.9 only security fixes topic-argument-clinic

Comments

@ericsnowcurrently
Copy link
Member

BPO 38141
Nosy @larryhastings, @ericsnowcurrently, @serhiy-storchaka, @tahia-khan

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/ericsnowcurrently'
closed_at = None
created_at = <Date 2019-09-12.14:59:42.372>
labels = ['expert-argument-clinic', '3.9']
title = 'Use fewer statics in Argument Clinic.'
updated_at = <Date 2019-09-26.17:28:25.844>
user = 'https://github.com/ericsnowcurrently'

bugs.python.org fields:

activity = <Date 2019-09-26.17:28:25.844>
actor = 'ta1hia'
assignee = 'eric.snow'
closed = False
closed_date = None
closer = None
components = ['Argument Clinic']
creation = <Date 2019-09-12.14:59:42.372>
creator = 'eric.snow'
dependencies = []
files = []
hgrepos = []
issue_num = 38141
keywords = []
message_count = 5.0
messages = ['352193', '352226', '352306', '352310', '352311']
nosy_count = 4.0
nosy_names = ['larry', 'eric.snow', 'serhiy.storchaka', 'ta1hia']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue38141'
versions = ['Python 3.9']

@ericsnowcurrently
Copy link
Member Author

(This is a sub-task of bpo-36876, "Global C variables are a problem.".)

Currently Argument Clinic generates "_PyArg_Parser _parser" as a static variable. Dropping "static" solves the problem of thread safety (e.g. for subinterpreters not sharing the GIL).

@ericsnowcurrently ericsnowcurrently added the 3.9 only security fixes label Sep 12, 2019
@ericsnowcurrently ericsnowcurrently self-assigned this Sep 12, 2019
@larryhastings larryhastings changed the title Use less statics in Argument Clinic. Use fewer statics in Argument Clinic. Sep 12, 2019
@serhiy-storchaka
Copy link
Member

Dropping "static" will hit performance. _PyArg_Parser is used at first place because it can cache some data between calls. If drop static, you should drop also _PyArg_Parser and return to old slow arguments parsing.

@serhiy-storchaka
Copy link
Member

Would adding a mutex for thread-safe initialization of _Py_Identifier and _PyArg_Parser solve the problem with subinterpreters?

@ericsnowcurrently
Copy link
Member Author

That might work. :)

There are two key problems under subinterpreters that do not share the GIL:

  • races on refcount operations
  • cache thrashing due to refcount operations (under multi-core threads)

A lock would certainly mitigate the first problem. I'm not sure how much the second would actually be a problem.

@larryhastings
Copy link
Contributor

shared objects x threads = contention for notification of invalidated cache lines

If you're not running multiple threads, there's no problem. If it's only a few shared objects, it probably wouldn't be a big deal. As they say in medicine: "the dose makes the poison."

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@kumaraditya303
Copy link
Contributor

Duplicate of #90928

@kumaraditya303 kumaraditya303 marked this as a duplicate of #90928 May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes topic-argument-clinic
Projects
None yet
Development

No branches or pull requests

4 participants