Skip to content

Speed up flake8-async by telling libcst to skip deepcopy.#438

Open
yilei wants to merge 2 commits intopython-trio:mainfrom
yilei:libcst-optimization
Open

Speed up flake8-async by telling libcst to skip deepcopy.#438
yilei wants to merge 2 commits intopython-trio:mainfrom
yilei:libcst-optimization

Conversation

@yilei
Copy link
Copy Markdown

@yilei yilei commented Apr 3, 2026

Why? The default deepcopy in libcst guards against the same CST node object appearing at two positions in the tree (metadata is keyed by node identity). In our use of libcst in flake8-async, the parser output and the result of a prior .visit() never share nodes, so the copy is wasted work. This stays safe as long as no visitor returns a cached CST node from multiple leave_* calls.

See pyref.dev/libcst.metadata.MetadataWrapper.__init__

Running the flake8-async tests on my machine now takes 29.81s instead of 38.95s with this change.

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.

1 participant