Skip to content

Commit

Permalink
Prevent compile timer from starting during load, because CodeMirror w…
Browse files Browse the repository at this point in the history
…as firing its onChange event after loading a new hash. This cuts page load time in half for systems relying on the ANGLE cross-compiler, because it compiles only once now, not twice.
  • Loading branch information
emackey committed Dec 24, 2011
1 parent d2ac5fd commit 8617669
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions server/assets/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function load_code(hash) {
set_parent_button('hidden');

$.getJSON('/item/'+hash, function(result) {
compileOnChangeCode = false; // Prevent compile timer start
code.setValue(result['code']);
original_code=code.getValue();

Expand All @@ -145,6 +146,7 @@ function load_code(hash) {
saveButton.textContent = 'fork';

compile();
compileOnChangeCode = true;
});
}

Expand Down
8 changes: 5 additions & 3 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
var toolbar, compileButton, fullscreenButton, compileTimer, errorLines = [];
var code, canvas, gl, buffer, currentProgram, vertexPosition,
parameters = { startTime: Date.now(), time: 0, mouseX: 0.5, mouseY: 0.5, screenWidth: 0, screenHeight: 0 },
frontTarget, backTarget, screenProgram, getWebGL, resizer = {};
frontTarget, backTarget, screenProgram, getWebGL, resizer = {}, compileOnChangeCode = true;

init();
if (gl) { animate(); }
Expand Down Expand Up @@ -283,8 +283,10 @@
indentUnit: 8,
mode: "text/x-glsl",
onChange: function () {
clearTimeout(compileTimer);
compileTimer = setTimeout(compile, 500);
if (compileOnChangeCode) {
clearTimeout(compileTimer);
compileTimer = setTimeout(compile, 500);
}
}
});
code.getWrapperElement().style.visibility = 'visible';
Expand Down
2 changes: 2 additions & 0 deletions static/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ function readURL( hash ) {

compressor.decompress( bytes, function( text ) {

compileOnChangeCode = false; // Prevent compile timer start
code.setValue(text);
compile();
compileOnChangeCode = true;

},
dummyFunction );
Expand Down

0 comments on commit 8617669

Please sign in to comment.