NetLogo / NetLogo/Tortoise

Performance of `=`, `!=`, `>=`, and `<=`

Open
#245 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
CoffeeScript
Stars
57
Forks
28
PR merge metrics
No merged PRs in 30d

Description

@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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the implementations of =, !=, >=, and <=, along with the compiler or runtime path for the shown while and foreach benchmark. Compare the operator and loop behavior without changing semantic integrity, and verify any optimization against the benchmark and existing operator tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
coffeescript, javascript
Domain
compilers, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.