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 of =, !=, >=, and <= #245

Open
CIVITAS-John opened this issue Sep 29, 2022 · 1 comment
Open

Performance of =, !=, >=, and <= #245

CIVITAS-John opened this issue Sep 29, 2022 · 1 comment

Comments

@CIVITAS-John
Copy link
Contributor

@maizi reports that the way we implement the three basic operators could be further optimized.

I did some inspection and at this time, my instinction is that the optimization of operators could be a key part to improve the performance of NLW. Specifically, >= and <= should have their own implementations. It won't be hard:

lte: (a, b) ->
  if (checks.isString(a) and checks.isString(b)) or (checks.isNumber(a) and checks.isNumber(b))
    a <= b
  else if typeof(a) is typeof(b) and a.compare? and b.compare?
    result = a.compare(b) 
    result is LT or result is EQ
  else
    throw exceptions.internal("Invalid operands to `lte`")

For = and !=, my intuition is that the null check is not necessary: if someone send in a null or undefined, just let it be. Since this would only happen when a primitive or an extension primitive accidentally leaks them, it is unnecessary to put those checks in place.

Those are not enough - see the following benchmark:
let i 0 let l length arr while[i < l][... set i i + 1]
performs much worse than foreach either with or without calculating the index.

However, my proposal is relatively safer to integrate without compromising the symantic integrity of NLW. If we could sacrifice this as well - probably with a compiler option - then we could do even more: override the valueOf and convert everything back to Javascript operators.

@CIVITAS-John
Copy link
Contributor Author

A quick implementation (not even touch the !=, only >=, <=, and =) on one of my computationally heavy models in TU shows ~8% improvement in performance.

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

1 participant