Open austinshenk opened 5 years ago
The length
property of strings is immutable, so caching it will only slightly reduce performance in modern browsers; it's already constant time to access. <
vs -
should also not make a noticeable difference, as code will be specialized to ints by the jit compiler. It's better to keep the code easy to read imo.
I went through and audited the for-loops and while-loops in VDOM's kernel code. I converted all of the forward iteration loops to use
length - i
instead ofi < length
and made sure the length value is being cached in a variable instead of being accessed each iteration. Example performance details are recorded in https://github.com/elm/core/pull/1000.I plan to take the changes I made and compare some benchmarks to show the results. These changes should not be destructive to existing functionality since I've tested a number of functions already and have not found anything that compromises it.