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
refactor: Move getNode
/canEnableFFmpegOptimizations
into a lazy loaded call
#9918
Conversation
… the first time it's actually ever referenced
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Ignored Deployments
|
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://discord-js-git-fork-jmtk-main-discordjs.vercel.app/ |
Codecov Report
@@ Coverage Diff @@
## main #9918 +/- ##
==========================================
- Coverage 60.22% 60.05% -0.18%
==========================================
Files 235 235
Lines 16114 16028 -86
Branches 1231 1216 -15
==========================================
- Hits 9705 9625 -80
+ Misses 6365 6359 -6
Partials 44 44
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today! |
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.
👍
getNode
/canEnableFFmpegOptimizations
into a lazy loaded callgetNode
/canEnableFFmpegOptimizations
into a lazy loaded call
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.
Alternative idea, what if we make NODES
nullable and initialize using nullish assignment?
Similar to:
const node = (NODES ??= initializeNodes()).get(type);
(Or splitting the expression in two lines). Obviously this change would make initializeNodes()
return a newly constructed map.
The reasoning behind this idea is so NODES
, being null rather than an empty map guards against the possible edge case of using an unitialized map elsewhere.
It would also remove the need for an extra variable and extra operations.
…ODES, this removes an extra variable and cleans up the code
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.
Needed for the ESLint check to pass:
Co-authored-by: Aura Román <kyradiscord@gmail.com>
Please run Prettier! |
Done! Didn't realize that space was still there |
Please describe the changes this PR makes and why it should be merged:
Lazy calls the functions in the root of
TransformerGraph.ts
, which are called the first time the file is imported(which is through any time @discordjs/voice is imported. More importantly, the call tocanEnableFFmpegOptimizations
, which is a loop that synchronously spawns child processes is now deferred until the first time you actually attempt to play audio.This improves bot startup time by 100ms for people importing @discordjs/voice:
Before:
After:
I tested this locally and can confirm audio plays correctly and the call is only called then.
Resolves #9859
Status and versioning classification: