aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test_core.py8
-rw-r--r--tools/find_bigfuncs.py2
-rw-r--r--tools/js_optimizer.py56
3 files changed, 44 insertions, 22 deletions
diff --git a/tests/test_core.py b/tests/test_core.py
index 2764c143..17707c44 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -8597,7 +8597,7 @@ def process(filename):
do_test()
# some test coverage for EMCC_DEBUG 1 and 2
- if self.emcc_args and '-O2' in self.emcc_args and 'EMCC_DEBUG' not in os.environ:
+ if self.emcc_args and '-O2' in self.emcc_args and 'EMCC_DEBUG' not in os.environ and '-g' in self.emcc_args:
shutil.copyfile('src.c.o.js', 'release.js')
try:
os.environ['EMCC_DEBUG'] = '1'
@@ -8612,7 +8612,8 @@ def process(filename):
del os.environ['EMCC_DEBUG']
for debug in [1,2]:
def clean(text):
- return text.replace('\n\n', '\n').replace('\n\n', '\n').replace('\n\n', '\n').replace('\n\n', '\n').replace('\n\n', '\n').replace('{\n}', '{}')
+ text = text.replace('\n\n', '\n').replace('\n\n', '\n').replace('\n\n', '\n').replace('\n\n', '\n').replace('\n\n', '\n').replace('{\n}', '{}')
+ return '\n'.join(sorted(text.split('\n')))
self.assertIdentical(clean(open('release.js').read()), clean(open('debug%d.js' % debug).read())) # EMCC_DEBUG=1 mode must not generate different code!
print >> sys.stderr, 'debug check %d passed too' % debug
@@ -9684,7 +9685,8 @@ def process(filename):
# optimizer can deal with both types.
out_file = re.sub(' *//@.*$', '', out_file, flags=re.MULTILINE)
def clean(code):
- return code.replace('{\n}', '{}')
+ code = code.replace('{\n}', '{}')
+ return '\n'.join(sorted(code.split('\n')))
self.assertIdentical(clean(no_maps_file), clean(out_file))
map_filename = out_filename + '.map'
data = json.load(open(map_filename, 'r'))
diff --git a/tools/find_bigfuncs.py b/tools/find_bigfuncs.py
index 79136343..c8e29833 100644
--- a/tools/find_bigfuncs.py
+++ b/tools/find_bigfuncs.py
@@ -18,6 +18,6 @@ for line in open(filename):
size = i - start
data.append([curr, size])
curr = None
-data.sort(lambda x, y: x[1] - y[1])
+#data.sort(lambda x, y: x[1] - y[1])
print ''.join(['%6d : %s' % (x[1], x[0]) for x in data])
diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py
index 5d7dc562..a11da7f0 100644
--- a/tools/js_optimizer.py
+++ b/tools/js_optimizer.py
@@ -205,23 +205,26 @@ EMSCRIPTEN_FUNCS();
pre = ''
post = ''
- # Pick where to split into chunks, so that (1) they do not oom in node/uglify, and (2) we can run them in parallel
- # If we have metadata, we split only the generated code, and save the pre and post on the side (and do not optimize them)
- parts = map(lambda part: part, js.split('\n}\n'))
- funcs = []
- for i in range(len(parts)):
- func = parts[i]
- if i < len(parts)-1: func += '\n}\n' # last part needs no }
- m = func_sig.search(func)
- if m:
- ident = m.group(2)
- else:
- if know_generated: continue # ignore whitespace
- ident = 'anon_%d' % i
- assert ident
- funcs.append((ident, func))
- parts = None
+ def split_funcs(js):
+ # Pick where to split into chunks, so that (1) they do not oom in node/uglify, and (2) we can run them in parallel
+ # If we have metadata, we split only the generated code, and save the pre and post on the side (and do not optimize them)
+ parts = map(lambda part: part, js.split('\n}\n'))
+ funcs = []
+ for i in range(len(parts)):
+ func = parts[i]
+ if i < len(parts)-1: func += '\n}\n' # last part needs no }
+ m = func_sig.search(func)
+ if m:
+ ident = m.group(2)
+ else:
+ if know_generated: continue # ignore whitespace
+ ident = 'anon_%d' % i
+ assert ident
+ funcs.append((ident, func))
+ return funcs
+
total_size = len(js)
+ funcs = split_funcs(js)
js = None
if 'last' in passes and len(funcs) > 0:
@@ -235,6 +238,7 @@ EMSCRIPTEN_FUNCS();
chunk_size = min(MAX_CHUNK_SIZE, max(MIN_CHUNK_SIZE, total_size / intended_num_chunks))
chunks = shared.chunkify(funcs, chunk_size, jcache.get_cachename('jsopt') if jcache else None)
+ funcs = None
if jcache:
# load chunks from cache where we can # TODO: ignore small chunks
@@ -324,9 +328,25 @@ EMSCRIPTEN_FUNCS();
filename += '.jo.js'
f = open(filename, 'w')
f.write(pre);
+ pre = None
+
+ # sort functions by size, to make diffing easier and to improve aot times
+ funcses = []
for out_file in filenames:
- f.write(open(out_file).read())
- f.write('\n')
+ funcses.append(split_funcs(open(out_file).read()))
+ funcs = [item for sublist in funcses for item in sublist]
+ funcses = None
+ def sorter(x, y):
+ diff = len(y[1]) - len(x[1])
+ if diff != 0: return diff
+ if x[0] < y[0]: return 1
+ elif x[0] > y[0]: return -1
+ return 0
+ funcs.sort(sorter)
+ for func in funcs:
+ f.write(func[1])
+ funcs = None
+ f.write('\n')
if jcache:
for cached in cached_outputs:
f.write(cached); # TODO: preserve order