Skip to content

Use a freelist for thread statesย #126096

@ZeroIntensity

Description

@ZeroIntensity

Feature or enhancement

Proposal:

Subinterpreter switching relies on allocating a new thread state every time we want to switch to the target interpreter. Unfortunately, thread states use the system malloc via the raw allocators, so there can be some overhead if there's a lot of switching going on, depending on the system and the state of it. This can be slightly optimized by using a thread-local freelist for thread states, instead of going straight to calloc every time.

I've measured a slight performance increase on my end (~2%), but this should but much better for systems with a lot less memory, where the allocator has to do a lot more work.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

Labels

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions