Skip to content

Commit 83c10dd

Browse files
tyomitchartyomsk
authored andcommitted
bpo-26415: reduce peak memory consumption by the parser
Compress some branchless stretches in the parse tree into a single node. AST is not affected.
1 parent 4f5a349 commit 83c10dd

12 files changed

Lines changed: 5036 additions & 200 deletions

File tree

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ Doc/library/token-list.inc linguist-generated=true
5959
Include/token.h linguist-generated=true
6060
Lib/token.py linguist-generated=true
6161
Parser/token.c linguist-generated=true
62+
Modules/gramvalid.c linguist-generated=true

Include/node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ PyAPI_FUNC(node *) PyNode_New(int type);
2222
PyAPI_FUNC(int) PyNode_AddChild(node *n, int type,
2323
char *str, int lineno, int col_offset,
2424
int end_lineno, int end_col_offset);
25+
PyAPI_FUNC(void) PyNode_Compress(node *n);
2526
PyAPI_FUNC(void) PyNode_Free(node *n);
2627
#ifndef Py_LIMITED_API
2728
PyAPI_FUNC(Py_ssize_t) _PyNode_SizeOf(node *n);

Makefile.pre.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,9 +794,11 @@ regen-grammar: regen-token
794794
$(PYTHON_FOR_REGEN) -m Parser.pgen $(srcdir)/Grammar/Grammar \
795795
$(srcdir)/Grammar/Tokens \
796796
$(srcdir)/Include/graminit.h.new \
797-
$(srcdir)/Python/graminit.c.new
797+
$(srcdir)/Python/graminit.c.new \
798+
$(srcdir)/Modules/gramvalid.c.new
798799
$(UPDATE_FILE) $(srcdir)/Include/graminit.h $(srcdir)/Include/graminit.h.new
799800
$(UPDATE_FILE) $(srcdir)/Python/graminit.c $(srcdir)/Python/graminit.c.new
801+
$(UPDATE_FILE) $(srcdir)/Modules/gramvalid.c $(srcdir)/Modules/gramvalid.c.new
800802

801803
.PHONY=regen-ast
802804
regen-ast:
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Reduce peak memory consumption by the parser, by compressing some
2+
branchless stretches in the parse tree into a single node. AST is
3+
not affected.

0 commit comments

Comments
 (0)