Skip to content

Minor Optimisations #179

Description

@MaxC25

I would have done a pull request had I been bothered to do a fork, but here are my things:
all instances of math.floor(n/2), such as the one in scripts/benchmark_check.ts should become n>>1, mathematically identical but faster as JS can not handle any iterable longer than 2^32-1 words, and the line,
return sorted.length % 2 === 0 ? (sorted[mid - 1]! + sorted[mid]!) / 2 : sorted[mid]!
could become
return sorted.length & 1 ? sorted[mid]! : (sorted[mid - 1]! + sorted[mid]!) / 2
which is equivilant but probably slightly faster, and if you don't like the re-ordering, you can do
return ~(sorted.length & 1) ? (sorted[mid - 1]! + sorted[mid]!) / 2 : sorted[mid]!

and in scripts/build-demo-site.ts

if (result.exitCode !== 0) {
  process.exit(result.exitCode)
}

could become

if (result.exitCode) {
  process.exit(result.exitCode)
}

, which I think is neater, with no performance disadvantages that I know of, and this can be generalised to replace all if(num!=0) with if(num)

Also, on line 330, process.exitCode = 1 maybe could become process.exitcode = 1&0xFF to make it obvious to the browser that this is not a float but an integer that fits in 8 bits, but take this with a grain of salt as this does feel a bit pointless and contradicts my previous point about neatness.

The same goes for adding |0 after integer declarations and simple reassignments e.g x=y to make it obvious to a bad compiler that it's an integer to maybe speed it up, but again, this feels pointless and probably is, alongside being not particularly elegant so I would not recommend it, but you can consider it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions