|
|
|
|
2007-08-01Advice for the OpenLaszlo optimizerSince the OpenLaszlo compiler does not do common-subexpression elimination, when you are trying to optimize things, pretend you are writing in 1985 C. Instead of:
say:
Even better, when you find yourself having to write a null check, ask yourself if it would be cleaner, simpler, and more efficient to have the variable you are referencing not be nullable. For instance, if a variable is an array, consider using an empty array for its initial value, rather than null. This is a time/space trade-off: if there are many operations on the array and the variable is almost always not null, it will be more efficient to use an empty array; if there are few operations and the variable is usually null, then not allocating the empty array is the better choice. (In Javascript 2, you will have the option of declaring a variable to be of a particular type, and you will have the option of declaring whether or not that variable can also be null. If you declare it not to be nullable, then the compiler will give you a compile-time warning if it cannot prove that the variable is never null, and it will insert the appropriate runtime check for you.
Even though we don’t yet support the type declarations, we can follow the pattern and be ready…) 2007-04-19Undefined reduxA reader from Maynard asks: Continue reading "Undefined redux" 2007-02-04Order in the codeA reader from San Mateo writes:
Gentle reader,
An object is just a hash table, and there is no implicit order of elements of a hash table (Java has If you want to iterate over an array’s entries in order, use
If you want to iterate over an object’s keys in a particular order, you have to pull the keys out into an array, sort that array, and then iterate over that array:
The fact that any particular runtime iterates over object keys in any particular order reveals an implementation detail of their hashes, but if you write your code to depend on that you are setting yourself up for a fall. Most Javascript runtimes just happen to use particularly trivial hash implementations that give you the illusion the keys are iterated in order. See also the yellow box caution here. |
|