Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Speed up :func:`ast.parse` by pausing the garbage collector while the AST is
converted to Python objects.
8 changes: 8 additions & 0 deletions Parser/asdl_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -2117,7 +2117,15 @@ class PartingShots(StaticVisitor):
if (state == NULL) {
return NULL;
}
// Freshly converted AST nodes cannot be part of a reference cycle yet,
// so a garbage collection while building them cannot free anything of
// this tree and only pays to traverse its half-built nodes. Pause the
// collector while the conversion runs.
int gc_was_enabled = PyGC_Disable();
PyObject *result = ast2obj_mod(state, t);
if (gc_was_enabled) {
PyGC_Enable();
}
return result;
}
Expand Down
8 changes: 8 additions & 0 deletions Python/Python-ast.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading