wiki:JavaScript performance improvement ideas

Version 1 (modified by, 13 years ago) (diff)


Some ideas gathered over time:

  • Make a JSGlobalObject class that needs to be used for an Interpreter's global object, and make Window subclass it. This would rRemove time spent in InterpreterMap hashtable, which should be a 1-2% improvement by itself. Various code needs to get from a global scope object back to the corresponding interpreter. If the global object was a specific JSObject subclass, it could store an interpreter to the global object directly. This change might also allow other simplifications.
  • Avoid creating wrapper objects just to access standard properties and methods of primitive values like strings and numbers. Mainly this is an issue for strings - numbers don't have that many interesting properties or methods. This one is slightly tricky. Ideally we'd call methods without making a wrapper at all, and just code them specially to work on the primitive value, or reuse a single wrapper per type when it's created implicitly for property access. However, there are ways that the implicit wrapper can be captured. Adding nonstandard methods or getters/setters to the prototype will make the implicit wrapper get exposed to arbitrary code, which could put it in a global variable or the like. So to make this work, we would need the wrapper to know that and swap itself out for a new reusable temporary wrapper when a custom property is accessed.
  • Have a version of toString conversion that gives a StringImp* instead of a UString, and try to code as much string handling as possible to return the same StringImp if something equal to the original string is getting returned.

  • Generational mostly-copying garbage collector. This one is likely to be pretty hard.
  • use bytecode or something similar to make the interpreter non-recursive so it doesn't use so much stack. But the inner loop has to be coded carefully because obvious ways of doing will regress performance instead of speeding it up.
  • Constant folding. This could be done purely by the parser, for strings, numbers, even regexps.
  • Special-case numeric code. If we can prove some values are guaranteed to be numeric, we could evaluate expressions involving them purely using doubles, without converting intermediate values to immediate values or NumberImps at all.