Skip to content

Commit c7e786a

Browse files
committed
Speed up py314
1 parent 2671785 commit c7e786a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

coconut/compiler/util.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
pseudo_targets,
107107
reserved_vars,
108108
packrat_cache_size,
109-
temp_grammar_item_ref_count,
109+
min_observed_ref_count,
110110
indchars,
111111
comment_chars,
112112
non_syntactic_newline,
@@ -987,6 +987,10 @@ def get_target_info_smart(target, mode="lowest"):
987987
def maybe_copy_elem(item, name):
988988
"""Copy the given grammar element if it's referenced somewhere else."""
989989
item_ref_count = sys.getrefcount(item) if CPYTHON and not on_new_python else float("inf")
990+
if isinstance(min_observed_ref_count, dict):
991+
temp_grammar_item_ref_count = min_observed_ref_count[name]
992+
else:
993+
temp_grammar_item_ref_count = min_observed_ref_count
990994
internal_assert(lambda: item_ref_count >= temp_grammar_item_ref_count, "add_action got item with too low ref count", (item, type(item), item_ref_count))
991995
if item_ref_count <= temp_grammar_item_ref_count:
992996
if DEVELOP:

coconut/constants.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import re
2727
import datetime as dt
2828
from warnings import warn
29+
from collections import defaultdict
2930

3031
# -----------------------------------------------------------------------------------------------------------------------
3132
# UTILITIES:
@@ -179,8 +180,8 @@ def get_path_env_var(env_var, default):
179180
test_computation_graph_pickling = False
180181

181182
# should be the minimal ref count observed by maybe_copy_elem
182-
temp_grammar_item_ref_count = (
183-
1 if PY314
183+
min_observed_ref_count = (
184+
defaultdict(lambda: 2, attach=1) if PY314
184185
else 4 if PY311
185186
else 5
186187
)

0 commit comments

Comments
 (0)