-
-
Notifications
You must be signed in to change notification settings - Fork 36
refactor(promise-helpers): reuse promise Symbol #2408
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
Conversation
Instead of asking the global namespace for it every time, store the reference and put access it faster each time it's used.
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe update introduces a new changeset documenting a patch for Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant PromiseHelpers
Caller->>PromiseHelpers: fakePromise()
PromiseHelpers->>PromiseHelpers: Tag with kFakePromise symbol
Caller->>PromiseHelpers: isFakePromise(obj)
PromiseHelpers->>PromiseHelpers: Check for kFakePromise symbol
Caller->>PromiseHelpers: fakeRejectPromise()
PromiseHelpers->>PromiseHelpers: Tag with kFakePromise symbol
Caller->>PromiseHelpers: isFakeRejectPromise(obj)
PromiseHelpers->>PromiseHelpers: Check for kFakePromise symbol
Possibly related PRs
Poem
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
.changeset/cruel-colts-show.md (1)
5-5
: Enhance changeset summary style
To follow conventional-commit and changeset conventions, consider prefixing with a type/scope (e.g.,perf(promise-helpers):
) and using lowercase for consistency:- Reuse fake promise Symbol + perf(promise-helpers): reuse fake promise symbol
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.changeset/cruel-colts-show.md
(1 hunks)packages/promise-helpers/src/index.ts
(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: unit / node 18
- GitHub Check: unit / node 20
- GitHub Check: unit / node 23
- GitHub Check: unit / node 22
- GitHub Check: unit / deno
- GitHub Check: unit / bun
- GitHub Check: node-fetch (consumeBody)
- GitHub Check: server (native)
🔇 Additional comments (4)
packages/promise-helpers/src/index.ts (4)
4-4
: Centralize and cache the fake-promise symbol lookup
Great improvement: caching the result ofSymbol.for
avoids repeated global lookups and standardizes the tag across the module.
92-93
: Consistently tag resolved fake promises
Adding[kFakePromise]: 'resolved'
ensures every fake-resolved promise carries the same identifier for later detection.
200-201
: Consistently tag rejected fake promises
Adding[kFakePromise]: 'rejected'
mirrors the resolved case and makes error‐path promises discoverable via the same symbol.
317-323
: Use the cached symbol in detection helpers
Refactoring bothisFakePromise
andisFakeRejectPromise
to rely onkFakePromise
aligns with the new tagging approach and removes string-based lookups.
Thanks for the PR but I actually didn't do anything with promise helpers in my PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR but I actually didn't do anything with promise helpers in my PR.
I'm aware. I'm just pointing it out, that in order to explain that this particular change may make it slightly faster, I need to compare against something earlier. Otherwise it would seems as if I made it slower 🙂
✅
|
✅
|
✅
|
✅
|
✅
|
Description
Instead of asking the global namespace for it every time, store the reference and put access it faster each time it's used.
Comparing to the published server v0.10.5 with #2383 reverted. I reverted it because even though removing of the
WeakMap
improves performance, the other changes make it dunk. When I picked changes from #1505 (and ended with the same approach as #2383 without removing public API), it was 3-5% faster.Fastify benchmarks against
node:http
.many runs, actually:
Type of change
Please delete options that are not relevant.
expected)
Screenshots/Sandbox (if appropriate/relevant):
n/a
Checklist:
CONTRIBUTING doc and the
style guidelines of this project
Further comments
This change based on current master:
Just master vs published
v0.10.5
: