Skip to content

Commit

Permalink
added --tune-gc to increase performance ~8.5% when processing multipl…
Browse files Browse the repository at this point in the history
…e files

this may cause peak memory usage to be higher
  • Loading branch information
msolo committed May 26, 2011
1 parent d8934aa commit 3e71378
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions spitfire/compiler/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy
import gc
import logging
import new
import os.path
Expand Down Expand Up @@ -144,7 +145,8 @@ class Compiler(object):
'optimizer_flags',
'output_directory',
'xspt_mode',
'include_path'
'include_path',
'tune_gc'
]

@classmethod
Expand Down Expand Up @@ -177,6 +179,8 @@ def __init__(self, **kargs):
self.locale = None
self.include_path = '.'
self.enable_filters = True
self.tune_gc = False

# the function registry is for optimized access to 'first-class' functions
# things that get accessed all the time that should be speedy
self.function_registry_file = None
Expand Down Expand Up @@ -264,9 +268,17 @@ def _reset(self):
self._source_code = None

def compile_template(self, src_text, classname):
self._reset()
self._parse_tree = parse_template(src_text, self.xspt_mode)
return self._compile_ast(self._parse_tree, classname)
if self.tune_gc:
gc.disable()
try:
self._reset()
self._parse_tree = parse_template(src_text, self.xspt_mode)
return self._compile_ast(self._parse_tree, classname)
finally:
if self.tune_gc:
self._reset()
gc.enable()
gc.collect()

def compile_file(self, filename):
self.src_filename = filename
Expand Down Expand Up @@ -360,4 +372,5 @@ def add_common_options(op):
help='file to use as the function registry')
op.add_option('-X', dest='optimizer_flags', action='append', default=[],
help=analyzer.AnalyzerOptions.get_help())
op.add_option('--tune-gc', action='store_true')

0 comments on commit 3e71378

Please sign in to comment.