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

gh-111968: Use per-thread freelists for dict in free-threading #114323

Merged
merged 25 commits into from
Feb 1, 2024

Conversation

corona10
Copy link
Member

@corona10 corona10 commented Jan 19, 2024

Copy link
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will want to keep the free-list state separate from the non-free-list related per-interpreter dictionary state (like watchers, and keys versions). I think the behavior would be incorrect if this were per-thread state.

Include/internal/pycore_freelist.h Outdated Show resolved Hide resolved
Include/internal/pycore_freelist.h Outdated Show resolved Hide resolved
Objects/dictobject.c Outdated Show resolved Hide resolved
@corona10 corona10 changed the title gh-111968: Use per-thread freelists for dict in free-threading [WIP] gh-111968: Use per-thread freelists for dict in free-threading Jan 19, 2024
@corona10
Copy link
Member Author

Thank you for catching, there was some mistake that I didn't catch the issue :(, I will update the soon.

@corona10 corona10 changed the title [WIP] gh-111968: Use per-thread freelists for dict in free-threading gh-111968: Use per-thread freelists for dict in free-threading Jan 19, 2024
Copy link
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a suggestion about the naming of "global_dict_state", but otherwise LGTM.

#define DICT_MAX_WATCHERS 8

struct _Py_dict_state {
struct _Py_global_dict_state {
Copy link
Contributor

@colesbury colesbury Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe _Py_dict_interp_state?

In some places we use "global_state" to mean runtime-global (not interpreter). For example, we have:

  • _dtoa_interp_state (per-interpreter)
  • _mimalloc_interp_state (per-interpreter)
  • _obmalloc_global_state (in PyRuntime)

@corona10 corona10 changed the title gh-111968: Use per-thread freelists for dict in free-threading [WIP] gh-111968: Use per-thread freelists for dict in free-threading Jan 20, 2024
@corona10 corona10 changed the title [WIP] gh-111968: Use per-thread freelists for dict in free-threading gh-111968: Use per-thread freelists for dict in free-threading Jan 20, 2024
@@ -41,6 +41,22 @@ struct _Py_long_state {
int max_str_digits;
};

#define DICT_MAX_WATCHERS 8

struct _Py_dict_interp_state {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@colesbury
More proper position might be pycore_dict.h but there are some header dependency issue.
So let's declare the _Py_dict_interp_state at here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, pycore_dict.h (or pycore_dict_state.h) seem like a better locations, but if there are technical reasons that is difficult, this does not seem like such a big deal either.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only real change is pulling the freelist out. Why can't the remainder stay in pycore_dict_state,h?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still possible, I guess :) I will revert about it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@corona10
Copy link
Member Author

corona10 commented Jan 30, 2024

@colesbury SInce I resolved the conflict, Can you please take a look again? cc @ericsnowcurrently

Copy link
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still looks good to me. As I understand it, the plan is to address Eric's three remaining comments in subsequent PRs.

@ericsnowcurrently
Copy link
Member

I thought "revert the PyDict_Fini() signature" was going to be done in this PR. I'm fine with doing it in a separate PR if that makes sense.

@corona10
Copy link
Member Author

corona10 commented Feb 1, 2024

I thought "revert the PyDict_Fini() signature" was going to be done in this PR. I'm fine with doing it in a separate PR if that makes sense.

@ericsnowcurrently
4a76399
Done! :) I will merge the PR!

Objects/dictobject.c Outdated Show resolved Hide resolved
Objects/dictobject.c Outdated Show resolved Hide resolved
@bedevere-app
Copy link

bedevere-app bot commented Feb 1, 2024

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@ericsnowcurrently
Copy link
Member

You already fixed it. 😄

@corona10
Copy link
Member Author

corona10 commented Feb 1, 2024

You already fixed it. 😄

But I like your suggestion :) That was more closer to my original intention, I updated it.

@corona10
Copy link
Member Author

corona10 commented Feb 1, 2024

I have made the requested changes; please review again

@ericsnowcurrently
Copy link
Member

FYI, I left a comment on the issue enumerating the things we punted on in this PR: #111968 (comment).

Copy link
Member

@ericsnowcurrently ericsnowcurrently left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@corona10 corona10 enabled auto-merge (squash) February 1, 2024 20:32
@corona10
Copy link
Member Author

corona10 commented Feb 1, 2024

FYI, I left a comment on the issue enumerating the things we punted on in this PR: #111968 (comment).

Thanks!

@corona10 corona10 merged commit 1390796 into python:main Feb 1, 2024
32 checks passed
@corona10 corona10 deleted the gh-111968-dict branch February 1, 2024 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants