dimdenGD / ultimate-express

The Ultimate Express. Fastest http server with full Express compatibility, based on µWebSockets.
Apache License 2.0
518 stars 15 forks source link

perf: simplify req.accepts* #56

Closed nigrosimone closed 6 days ago

nigrosimone commented 6 days ago

Bonus Improvements:

pkg-pr-new[bot] commented 6 days ago

Open in Stackblitz

npm i https://pkg.pr.new/dimdenGD/ultimate-express@56

commit: 6ff51e6

nigrosimone commented 6 days ago

@dimdenGD Maybe we can also cache accepts(this) initialization, eg: ?

 accepts(...types) {
    if (!this.#accepts) {
      this.#accepts = accepts(this);
    }
    return this.#accepts.types(...types);
  }

  acceptsCharsets(...charsets) {
    if (!this.#accepts) {
      this.#accepts = accepts(this);
    }
    return this.#accepts.charsets(...charsets);
  }

  acceptsEncodings(...encodings) {
    if (!this.#accepts) {
      this.#accepts = accepts(this);
    }
    return this.#accepts.encodings(...encodings);
  }

  acceptsLanguages(...languages) {
    if (!this.#accepts) {
      this.#accepts = accepts(this);
    }
    return this.#accepts.languages(...languages);
  }
dimdenGD commented 6 days ago

Probably no point in caching because calling that function just creates a class with no real work done until function is called