Hacker News new | ask | show | jobs
by laurent123456 1691 days ago
> type: "CREATE" | "REMOVE" | "CHANGE";

Since performance is a goal, why not define an enum and use integer values? I don't know about speed, but the resulting diff would be smaller.

Also I wonder what "const t = true" is for.

1 comments

Usually it doesn’t make a difference neither in speed, nor in size, because of “interning” of literals. Unless you jsonify it, of course. It could show up, if you’d later compare .type with some “CRE”+”ATE” values made funny way, but not for literals, e.g.:

  // x.js
  export const foo = "foo"

  // y.js
  if (x.foo === "foo") {
    // ^ as cheap as int
  }

  const foo2 = "FOO".toLowerCase()
  if (x.foo === foo2) {
    // ^ questionable
    // depends on jit/optimization
  }
https://stackoverflow.com/questions/5276915/do-common-javasc...

https://en.wikipedia.org/wiki/String_interning