Opened 4 months ago

Last modified 7 days ago

#36983 new Cleanup/optimization

Improve free-threading performance

Reported by: Sam Gross Owned by:
Component: Core (Other) Version: 6.0
Severity: Normal Keywords:
Cc: Sam Gross, Simon Charette, Mykhailo Havelia Triage Stage: Someday/Maybe
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I’m a CPython core developer working on free-threading. Would the Django team be interested in reviewing patches aimed at improving Django's performance on free-threaded Python (e.g., 3.14t)?

For example, there are a few scaling bottlenecks caused by creating temporary Field instances, such as in rel_db_type(). This can lead to contention on the shared creation_counter and also invalidate CPython’s attribute lookup cache. I expect most of the patches to be fairly small.

For context, I’m using Zulip to identify and investigate these issues, and I’m also working to fix the underlying problems in CPython upstream where possible.

Change History (16)

comment:1 by Natalia Bidart, 4 months ago

Component: UncategorizedCore (Other)

Hello Sam! Thank you for the ticket and for the suggestion to improve Django's performance on free-threaded Python.

I think this is a generous offer, and that Django would benefit from this work. Since Django is a community-driven project, the best place to discuss this proposal is on the Django Forum. Please consider opening a topic in the “Django Internals” category outlining your proposal. It would also be very helpful if you could share some details about the issues you have identified so far.

I'll make sure to subscribe to the forum post and monitor the replies. Once there is discussion and community interest on the forum, we can reopen and accept the ticket if there is clear agreement to proceed.

comment:3 by Simon Charette, 4 months ago

Cc: Simon Charette added

comment:4 by Jacob Walls, 4 months ago

Triage Stage: UnreviewedSomeday/Maybe

I agree with Natalia that Django will benefit from this work. Reception was positive on the forum. Adjusting the triage state to reflect the "long-term changes" aimed at here.

comment:5 by Mykhailo Havelia, 3 months ago

Cc: Mykhailo Havelia added

comment:6 by Carlton Gibson, 5 weeks ago

Has patch: set

comment:7 by Jacob Walls <jacobtylerwalls@…>, 2 weeks ago

In 5d489a5:

Refs #36983 -- Skipped GC specific tests when GIL disabled.

comment:8 by Jacob Walls, 2 weeks ago

Has patch: unset

comment:9 by Carlton Gibson, 9 days ago

Has patch: set

New PR adds GHA CI runs against Python 3.13t and 3.14t.

comment:10 by Carlton Gibson, 8 days ago

Patch needs improvement: set

Still small numbers of (maybe intermittent) test failures to investigate on PR branch.

comment:11 by Carlton Gibson, 8 days ago

Patch needs improvement: unset

Fixed the test failures on the 3.13t and 3.14t runs, so should be good for a review.

comment:12 by Simon Charette, 8 days ago

Left some comments on the PR.

I think we should consider explicitly not supporting/testing against 3.13t given it systematically immortalize locally scoped class objects which Django dynamically creates a ton of via type(name, bases, attrs) (e.g. think of formset/inline usage in the admin) and will result in memory leaks.

comment:13 by Carlton Gibson, 8 days ago

I think we should consider explicitly not supporting/testing against 3.13t…

Agreed. Dropped it from the test matrix in the PR.

comment:14 by Jacob Walls <jacobtylerwalls@…>, 7 days ago

In 726440a4:

Refs #36983 -- Added CI tests on free-threaded Python 3.13t and 3.14t.

comment:15 by Jacob Walls <jacobtylerwalls@…>, 7 days ago

In cae38ec:

Refs #36983 -- Fixed race condition in ExceptionReporterTests under free-threading.

comment:16 by Jacob Walls, 7 days ago

Has patch: unset
Note: See TracTickets for help on using tickets.
Back to Top