-
Couldn't load subscription status.
- Fork 358
Improve overall iteration performance #1000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- convert forward iterating while loop into a reverse iterating one
|
I tested the performance of the I then setup tests to check the original performance to the new performance I recently committed in 79b0673. Below is a screenshot of the console timers for the function calls. I ran them 3 times as that is the suggested way to see the cached and uncached run times of a function. The performance difference is quite significant and similar results are seen on smaller sets. I also verified the function's results were not altered by using an alphabet string. I have not verified the higher and lower order characters yet, but was planning to do that. |
- convert while loop to a decrementing while loop with a simple conditional
|
I tried out a variation of the decrementing while loop by instead making it an incrementing one with a similar conditional. Hadn't really thought of doing it this way before. This allows most functions to maintain their body functionality while also easily gaining the performance boost. |
-This still retains the performance boost but also allows the loops to be consumed in a normal way instead of thinking of everything backwards
|
Performance results of All of these functions were tested against a 1 million character string and running against the same inputs. |
|
Nice! Which browsers have you tested this on? |
|
I've been testing this just on Chrome. I want to setup some test cases on an online performance tester so I can test it in multiple browsers and multiple platforms. |
|
I was taking a look at I haven't tested it at all, but it should construct the cons structure for a list as it iterates through the provided list cons. |
|
It is really risky to change a bunch of things like this, so I think the next step should be:
If the results show good results on certain specific functions, they may make sense as individual pull requests. That way they can be considered in isolation from other changes which may not have as good results, or may be different for some other reason. One aspect to consider is that JS VMs change over time, so it may be reasonable to just leave things as is knowing that whatever moment we optimize things, it may be different down the line. Anyway, in the meantime, I think it makes sense to close here and try to do those three steps. |




Multiple modules in core loop through list, arrays, and objects in various ways. Some can't be improved like the while cons, but there are a number of them that could be restructured to gain quite a bit of performance for not much, or any, file size increase.
A performance test bench detailed here shows many cases where a decrementing while loop with a simple conditional is the fastest looping structure.
I know this can't always be achieved given the functionality of the loop, but in the worst case we can ensure small improvements. For example, I've found various cases where a for-loop's length could be cached so it is not having to be calculated every iteration. It sounds small, but it even has better performance.
I'm planning to implement and test many of the areas I've found and report on the results for performance and also verifying functionality was not altered.