Comment #3 on issue 4165 by [email protected]: Slow creation of objects of functions
https://code.google.com/p/v8/issues/detail?id=4165

I chose to present a microbenchmark because it allowed you to quickly identify the cause of this bug. I do see this bug being rare in clients, but my feeling is that it is not uncommon amongst server-side middlewares and these libraries get executed on each request.

Let me try to explain how jade implements this. Jade allows mixins that can contain more types of characters than are valid in JS variables, so they are stored within objects with their names as key. Specifically,

mixin print-thing (thing)
  p= thing.a
  p= thing.b

html
  head
    title Fortunes
  body
    p Interesting website
    each thing in self.things
      +printThing(thing)


will yield the following JavaScript:

function(locals, jade) {
var jade_html = "";
var jade_mixins = {};
var jade_interp;
var self = locals || {};
jade_mixins["print-thing"] = function(thing){
var block = (this && this.block), attributes = (this && this.attributes) || {}; jade_html += "<p>" + (jade.escape(null == (jade_interp = thing.a) ? "" : jade_interp)) + "</p><p>" + (jade.escape(null == (jade_interp = thing.b) ? "" : jade_interp)) + "</p>";
};
jade_html += "<html><head><title>Fortunes</title></head><body><p>Interesting website</p>";
var $$i0obj = self.things;
  for (var $$i0 = 0, $$i0l = $$i0obj.length; $$i0 < $$i0l; $$i0++) {
    var thing = $$i0obj[$$i0];

jade_mixins["print-thing"](thing);
  }

}

jade_html += "</body></html>";;return jade_html;
}


Therefore, on each server request, this line will run:
jade_mixins["print-thing"] = function(thing){

I find it very unintuitive to fix this with
var jade_mixin_0;
jade_mixins["printThing"] = jade_mixin_0 = function(thing){


I have no idea how much effort is required to fix this, but it would be awesome if it could get fixed :)

--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to