Skip to content

Commit f89de12

Browse files
committedOct 29, 2012
do not use process pool for js optimizer when not enough cores or on windows (issue 663)
1 parent 3e8911f commit f89de12

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed
 

‎tests/runner.py

+3
Original file line numberDiff line numberDiff line change
@@ -5934,6 +5934,9 @@ def do_test():
59345934
del os.environ['EMCC_DEBUG']
59355935
shutil.copyfile('src.c.o.js', 'debug.js')
59365936
self.assertIdentical(open('release.js').read().replace('\n\n', '\n').replace('\n\n', '\n'), open('debug.js').read().replace('\n\n', '\n').replace('\n\n', '\n')) # EMCC_DEBUG=1 mode must not generate different code!
5937+
print >> sys.stderr, 'debug check passed too'
5938+
else:
5939+
print >> sys.stderr, 'not doing debug check because already in debug'
59375940

59385941
def test_python(self):
59395942
if Settings.QUANTUM_SIZE == 1: return self.skip('TODO: make this work')

‎tools/js_optimizer.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ def path_from_root(*pathelems):
99

1010
BEST_JS_PROCESS_SIZE = 1024*1024
1111

12+
WINDOWS = sys.platform.startswith('win')
13+
1214
def run_on_chunk(command):
1315
filename = command[2] # XXX hackish
1416
output = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0]
@@ -59,12 +61,27 @@ def run(filename, passes, js_engine):
5961
commands = map(lambda chunk: [js_engine, JS_OPTIMIZER, chunk] + passes, chunks)
6062

6163
if len(chunks) > 1:
62-
cores = min(multiprocessing.cpu_count(), chunks)
63-
if os.environ.get('EMCC_DEBUG'): print >> sys.stderr, 'splitting up js optimization into %d chunks, using %d cores' % (len(chunks), cores)
64-
pool = multiprocessing.Pool(processes=cores)
64+
# We are splitting into chunks. Hopefully we can do that in parallel
6565
commands = map(lambda command: command + ['noPrintMetadata'], commands)
66-
filenames = pool.map(run_on_chunk, commands, chunksize=1)
6766
filename += '.jo.js'
67+
68+
fail = None
69+
cores = min(multiprocessing.cpu_count(), chunks)
70+
if cores < 2:
71+
fail = 'python reports you have %d cores' % cores
72+
elif WINDOWS:
73+
fail = 'windows (see issue 663)'
74+
75+
if not fail:
76+
# We can parallelize
77+
if os.environ.get('EMCC_DEBUG'): print >> sys.stderr, 'splitting up js optimization into %d chunks, using %d cores' % (len(chunks), cores)
78+
pool = multiprocessing.Pool(processes=cores)
79+
filenames = pool.map(run_on_chunk, commands, chunksize=1)
80+
else:
81+
# We can't parallize, but still break into chunks to avoid uglify/node memory issues
82+
if os.environ.get('EMCC_DEBUG'): print >> sys.stderr, 'splitting up js optimization into %d chunks (not in parallel because %s)' % (len(chunks), fail)
83+
filenames = [run_on_chunk(command) for command in commands]
84+
6885
f = open(filename, 'w')
6986
for out_file in filenames:
7087
f.write(open(out_file).read())

0 commit comments

Comments
 (0)