Revision: 4408
Author:   [email protected]
Date:     Wed Mar 23 16:03:12 2011
Log:      cosmetic speedup to the markdown example
http://codereview.appspot.com/4279069

the markdown example is noticeably sluggish, even when you're just
using arrow keys to move the cursor around.  what happens is: every
keypress in the textarea sets a 'dirty' flag, and every 250ms, if
dirty is true, the textarea is converted to html, whether or not the
actual text has changed.  so if you hold down an arrow key, you
can see the cursor pause its motion every 1/4  second.

the slow part is converter.makeHtml(), and I'll dig into that some
more, but independent of that, we don't need to redo the text-to-html
conversion if the text doesn't changed.

this CL does that optimization.  (which is an easy optimation that
I think is reasonable to expect gadget writers to do, since this
type of optimization helps performance outside of Caja too)

[email protected]

http://code.google.com/p/google-caja/source/detail?r=4408

Modified:
 /trunk/src/com/google/caja/demos/playground/examples/markdown.html

=======================================
--- /trunk/src/com/google/caja/demos/playground/examples/markdown.html Mon Mar 21 12:14:40 2011 +++ /trunk/src/com/google/caja/demos/playground/examples/markdown.html Wed Mar 23 16:03:12 2011
@@ -1666,12 +1666,14 @@
 var r=document.getElementById("result");
 var t=document.getElementById("source");
 var w=document.getElementById("working");
+var valueRendered = '';
 var dirty = 1;
 function f() {
-  if (dirty) {
+  if (dirty && t.value !== valueRendered) {
     dirty = 0;
     w.innerHTML="Working...";
     r.innerHTML=converter.makeHtml(t.value);
+    valueRendered = t.value;
     w.innerHTML="";
   }
   setTimeout(f, 250);

Reply via email to