Skip to content
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

Performance tweaks #22

Closed
wants to merge 5 commits into from
Closed

Performance tweaks #22

wants to merge 5 commits into from

Commits on Sep 18, 2013

  1. Performance tweaks

    The table.insert command re-hash the table on every insert, using the # operator to find the last integer key of the table eliminates this overhead, and result in 1.5x to 17x performance boost across different benchmarks.
    
    This:
    	t[#t+1] = value
    Is a lot faster than this (even in localized LuaJIT):
    	table.insert(t, value)
    
    Some published benchmark result:
    http://blog.jgc.org/2013/04/performance-of-array-creation-in-lua.html
    
    The only draw back is that the # operator doesn't actually count the numbers of items in the table (according to http://lua-users.org/wiki/TablesTutorial), which isn't needed anyway when items are being sequentially inserted.
    
    We have been using the # operator in production for months without any issue, in fact we no longer have "local table.insert" in any of our codes.
    
    We highly recommend you guys to replace all the table.insert across all lua codes with t[#t+1] = x and gain extra performances.
    
    Thanks for the hard work agentzh, keep it up!
    alex-yam committed Sep 18, 2013
    Configuration menu
    Copy the full SHA
    c5ae8d1 View commit details
    Browse the repository at this point in the history

Commits on Sep 19, 2013

  1. Performance tweaks

    More performance tweaks recommended by agentzh
    alex-yam committed Sep 19, 2013
    Configuration menu
    Copy the full SHA
    1bab7ed View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    9e23e64 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    be8fca3 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    601dafc View commit details
    Browse the repository at this point in the history