ruff
79470e31 - [`isort`] Avoid constructing `glob::Pattern`s for literal known modules (#25123)

Commit
76 days ago
[`isort`] Avoid constructing `glob::Pattern`s for literal known modules (#25123) Summary -- For repositories with many known isort modules and a large number of extended configuration files, Ruff can consume a lot of memory. This is especially problematic in an LSP context, where this memory hangs around for the duration of the session. Codex and I tracked this down to the overhead of constructing `glob::Pattern`s for each `KnownModule`. I initially tried a more complicated approach of interning each `Pattern` during configuration resolution, but I suspected that the common case for projects with large numbers of known modules would be plain string literal patterns that don't need the `glob` infrastructure. This assumption was supported in the repository I was testing on, which saw a ~7x decrease in peak memory usage, which was only very slightly less than I saw with the interned version. There's probably something more general we could do here, as this comment alludes to: https://github.com/astral-sh/ruff/blob/c09080468ab6ef2d3e674043d310f21ec074d219/crates/ruff_workspace/src/resolver.rs#L311-L314 but this seemed like an easy first step for a known issue. Test plan -- A couple of new unit tests for the `IdentifierPattern` enum (as well as existing `isort` tests) and some manual testing on a large repo
Author
Parents
Loading