MCPcopy
hub / github.com/Nuitka/Nuitka / optimizeCompiledPythonModule

Function optimizeCompiledPythonModule

nuitka/optimizations/Optimization.py:66–161  ·  view source on GitHub ↗
(module)

Source from the content-addressed store, hash-verified

64
65
66def optimizeCompiledPythonModule(module):
67 module_name = module.getFullName()
68
69 optimization_logger.info_if_file(
70 "Doing module local optimizations for '{module_name}'.".format(
71 module_name=module_name
72 ),
73 other_logger=progress_logger,
74 )
75
76 touched = False
77
78 # TODO: Make this an option for the user to control instead.
79 if isShowProgress() and isShowMemory():
80 memory_watch = MemoryWatch()
81
82 # Temporary workaround, since we do some optimization based on the last pass results
83 # that are then not yet fully seen in the traces yet until another time around, we
84 # allow to continue the loop even without changes one more time.
85 unchanged_count = 0
86
87 # Count the micro passes, so we can see how often we looped
88 micro_pass = 0
89
90 while True:
91 micro_pass += 1
92
93 # Indicator that new variables or changed were added in the previous
94 # pass, will require another pass to fully propagate.
95 added_variables = "changed_variable_usage" in tag_set
96 tag_set.clear()
97
98 try:
99 # print("Compute module")
100 with withChangeIndicationsTo(signalChange):
101 scopes_were_incomplete = module.computeModule()
102 except SystemExit:
103 raise
104 except BaseException:
105 general.info("Interrupted while working on '%s'." % module)
106 raise
107
108 if scopes_were_incomplete or added_variables:
109 tag_set.add("var_usage")
110 added_variables = False
111
112 Graphs.onModuleOptimizationStep(module)
113
114 if (
115 unchanged_count == 1
116 and tag_set
117 and not isExperimental("ignore-extra-micro-pass")
118 ):
119 optimization_logger.sysexit(
120 """\
121Changes made after there were already no changes for module '%s' \
122in the extra micro pass that checks for that to not happen \
123that is done in debug mode: '%s'""" % (module_name, tag_set.asString()),

Callers 1

optimizeModuleFunction · 0.85

Calls 15

finishMethod · 0.95
isShowProgressFunction · 0.90
isShowMemoryFunction · 0.90
MemoryWatchClass · 0.90
isExperimentalFunction · 0.90
considerUsedModulesFunction · 0.90
withChangeIndicationsToFunction · 0.85
getFullNameMethod · 0.80
info_if_fileMethod · 0.80
computeModuleMethod · 0.80
clearMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…