Skip to content

Commit ef14a68

Browse files
committed
Force all deserialized objects to the oldest generation
1 parent 3fcfcb8 commit ef14a68

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

mypy/build.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,8 +3326,22 @@ def process_graph(graph: Graph, manager: BuildManager) -> None:
33263326
#
33273327
# TODO: see if it's possible to determine if we need to process only a
33283328
# _subset_ of the past SCCs instead of having to process them all.
3329+
if platform.python_implementation() == "CPython":
3330+
# When deserializing cache we create huge amount of new objects, so even
3331+
# with our generous GC thresholds, GC is still doing a lot of pointless
3332+
# work searching for garbage. So, we temporarily disable it when
3333+
# processing fresh SCCs, and then move all the new objects to the oldest
3334+
# generation with the freeze()/unfreeze() trick below. This is arguably
3335+
# a hack, but it gives huge performance wins for large third-party
3336+
# libraries, like torch.
3337+
gc.collect()
3338+
gc.disable()
33293339
for prev_scc in fresh_scc_queue:
33303340
process_fresh_modules(graph, prev_scc, manager)
3341+
if platform.python_implementation() == "CPython":
3342+
gc.freeze()
3343+
gc.unfreeze()
3344+
gc.enable()
33313345
fresh_scc_queue = []
33323346
size = len(scc)
33333347
if size == 1:

0 commit comments

Comments
 (0)