Skip to content

Update mimalloc version to 0.1.52 - #27586

Open
chirizxc wants to merge 3 commits into
astral-sh:mainfrom
chirizxc:patch-3
Open

Update mimalloc version to 0.1.52#27586
chirizxc wants to merge 3 commits into
astral-sh:mainfrom
chirizxc:patch-3

Conversation

@chirizxc

@chirizxc chirizxc commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

close #24880

Seems crash fixed in 0.1.51

Updated mimalloc version from 0.1.49 to 0.1.52 with v3 features.
Updated mimalloc feature from 'v3' to 'win_direct_tls'.
Comment thread Cargo.toml Outdated
matchit = { version = "0.9.0" }
memchr = { version = "2.7.1" }
mimalloc = { version = "0.1.49", features = ["v2"] }
mimalloc = { version = "0.1.52", features = ["win_direct_tls"] }

@chirizxc chirizxc Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you say more about the motivation for enabling this option and why you think it's correct? I'm not familiar with TLS but codex tells me that the number of TLS can be environment specific, meaning, it can be out of Ruff's control.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

mimalloc makes only two calls to TlsAlloc(): _mi_theap_default_slot and _mi_theap_cached_slot, however, what matters here isn't the calls themselves, but which indices have already been occupied by the process prior to mimalloc

In other words, mimalloc calls must fall within the range 0..63.

The first 64 slots are fast because they are physically embedded directly into the TEB (Thread Environment Block) structure at a fixed offset, and accessing them requires only a single read instruction via a segment register (gs/fs), without any additional pointer dereferencing.

Windows guarantees a minimum of 64 TLS indices per process, and modern versions of Windows can have up to 1,088.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

microsoft/mimalloc#1359

Maybe we shouldn't enable this feature, since it's random

@astral-sh-bot

astral-sh-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@MichaReiser

Copy link
Copy Markdown
Member

Do you have access to a windows machine? It would be great to run some benchmarks to verify that v3 is an improvement. I'm interested in walltime and peak RSS, ideally measured for lint and format across multiple ecosystem projects.

I'm asking because I'm very confused about mimalloc's versioning. v2 is stable and v3 is recommended. I've no idea what this is supposed to mean 😆

@chirizxc

chirizxc commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

Do you have access to a windows machine? It would be great to run some benchmarks to verify that v3 is an improvement. I'm interested in walltime and peak RSS, ideally measured for lint and format across multiple ecosystem projects.

I'm asking because I'm very confused about mimalloc's versioning. v2 is stable and v3 is recommended. I've no idea what this is supposed to mean 😆

Machine

изображение

ruff check . --isolated --no-cache

изображение

ruff format . --isolated --no-cache --check

изображение

@chirizxc

chirizxc commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

I'm asking because I'm very confused about mimalloc's versioning. v2 is stable and v3 is recommended. I've no idea what this is supposed to mean 😆

v2 - Uses thread-local segments to reduce memory fragmentation; architecture is frozen and only receives bug/security fixes — minimal change surface, maximum behavioral predictabilit

v3 - Simplified lock-free design with improved memory sharing across threads; can reduce memory usage on certain large workloads; supports fully first-class heaps (allocation from any thread, not just the creating one) and more efficient heap-walking, useful for e.g. CPython's GC

Source: https://github.com/microsoft/mimalloc/tree/dev3#versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upgrade to mimalloc v3

2 participants