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

Optimize functions that use GetTime() multiple times by calling GetTime() just once (when possible/meaningful to do so) #1292

Closed
dsidirop opened this issue Jun 2, 2024 · 0 comments

Comments

@dsidirop
Copy link
Contributor

dsidirop commented Jun 2, 2024

Given that GetTime() reaches out all the way to the underlying OS it kinda makes sense to snapshot and reuse the timestamps it generates when possible. An example of before-after:

Before:

visibilityscan:SetScript("OnUpdate", function()
  if (this.limit or 1) > GetTime() then return end

  this.limit = GetTime() + .2
  [...]

After:

visibilityscan:SetScript("OnUpdate", function()
  local now = GetTime()
  if (this.limit or 1) > now then
    return
  end

  this.limit = now + .2
  [...]
@dsidirop dsidirop changed the title Optimize functions that use GetTime() multiple times by calling GetTime() just once (when possible to do so) Optimize functions that use GetTime() multiple times by calling GetTime() just once (when possible/meaningful to do so) Jun 2, 2024
@shagu shagu closed this as completed Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants