diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-12-04 13:07:37 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-12-04 13:07:37 -0800 |
commit | 4385bdddb0594c6a5a05b74c540dc194d7b3a562 (patch) | |
tree | 4283ff5768eea8164648d8e0ffc20f299597a2a2 /src | |
parent | 0dd6e0f630529d6a56439e19ae1738c82a117393 (diff) |
batch function lines to speed up processing of many tiny functions
Diffstat (limited to 'src')
-rw-r--r-- | src/intertyper.js | 11 | ||||
-rw-r--r-- | src/jsifier.js | 27 |
2 files changed, 25 insertions, 13 deletions
diff --git a/src/intertyper.js b/src/intertyper.js index 03fbf072..417f6588 100644 --- a/src/intertyper.js +++ b/src/intertyper.js @@ -23,9 +23,9 @@ var NSW_NUW = set('nsw', 'nuw'); // Intertyper -function intertyper(data, sidePass, baseLineNum) { +function intertyper(data, sidePass, baseLineNums) { var mainPass = !sidePass; - baseLineNum = baseLineNum || 0; + baseLineNums = baseLineNums || [[0,0]]; // each pair [#0,#1] means "starting from line #0, the base line num is #1" dprint('framework', 'Big picture: Starting intertyper, main pass=' + mainPass); @@ -67,10 +67,15 @@ function intertyper(data, sidePass, baseLineNum) { }; unparsedBundles.push(unparsedGlobals); } + var baseLineNumPosition = 0; for (var i = 0; i < lines.length; i++) { var line = lines[i]; lines[i] = null; // lines may be very very large. Allow GCing to occur in the loop by releasing refs here + while (baseLineNumPosition < baseLineNums.length-1 && i >= baseLineNums[baseLineNumPosition+1][0]) { + baseLineNumPosition++; + } + if (mainPass && (line[0] == '%' || line[0] == '@')) { // If this isn't a type, it's a global variable, make a note of the information now, we will need it later var testType = /[@%\w\d\.\" ]+ = type .*/.exec(line); @@ -104,7 +109,7 @@ function intertyper(data, sidePass, baseLineNum) { } else { ret.push({ lineText: line, - lineNum: i + 1 + baseLineNum + lineNum: i + 1 + baseLineNums[baseLineNumPosition][1] }); if (/^\ +switch\ .*/.test(line)) { // beginning of llvm switch diff --git a/src/jsifier.js b/src/jsifier.js index df2ae43f..b6434455 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -108,17 +108,24 @@ function JSify(data, functionsOnly, givenFunctions) { } }); - // TODO: batch small functions - for (var i = 0; i < data.unparsedFunctions.length; i++) { - var func = data.unparsedFunctions[i]; - // We don't need to save anything past here - data.unparsedFunctions[i] = null; - dprint('unparsedFunctions', '====================\n// Processing |' + func.ident + '|, ' + i + '/' + data.unparsedFunctions.length); - if (DEBUG_MEMORY) MemoryDebugger.tick('pre-func ' + func.ident); - JSify(analyzer(intertyper(func.lines, true, func.lineNum-1)), true, Functions); - if (DEBUG_MEMORY) MemoryDebugger.tick('func ' + func.ident); + + var MAX_BATCH_FUNC_LINES = 1000; + while (data.unparsedFunctions.length > 0) { + var currFuncLines = []; + var currBaseLineNums = []; + while (currFuncLines.length == 0 || + (data.unparsedFunctions.length > 0 && currFuncLines.length + data.unparsedFunctions[0].lines.length <= MAX_BATCH_FUNC_LINES)) { + currBaseLineNums.push([currFuncLines.length, data.unparsedFunctions[0].lineNum-1]); + currFuncLines = currFuncLines.concat(data.unparsedFunctions[0].lines); // for first one, assign, do not concat? + data.unparsedFunctions.shift(); + } + dprint('unparsedFunctions','====================\n// Processing function batch of ' + currBaseLineNums.length + + ' functions, ' + currFuncLines.length + ' lines, functions left: ' + data.unparsedFunctions.length); + if (DEBUG_MEMORY) MemoryDebugger.tick('pre-func'); + JSify(analyzer(intertyper(currFuncLines, true, currBaseLineNums)), true, Functions); + if (DEBUG_MEMORY) MemoryDebugger.tick('post-func'); } - func = null; // Do not hold on to anything from inside that loop (JS function scoping..) + currFuncLines = currBaseLineNums = null; // Do not hold on to anything from inside that loop (JS function scoping..) data.unparsedFunctions = null; // Actors |