Skip to content

Defer calling canEnableFFmpegOptimizations on module load #9859

@JMTK

Description

@JMTK

Which package is this bug report for?

@discord.js/voice

Issue description

On app startup, I noticed that there were calls to canEnableFFmpegOptimizations(), despite not actually doing anything with voice for some testing I was doing. I do include discord.js/voice code elsewhere. It seems like in https://github.com/discordjs/voice/blob/309ac8596cac422cf22e51331869e011c720124c/src/audio/TransformerGraph.ts#L169, it is calling it just when the module is require/imported. I think this could be moved elsewhere somehow to only call it the first time the nodes are actually referenced somewhere, which should improve app startup time.

Code sample

  1. bot.js:
import Discord from 'discord.js';
import * as DiscordVoice from '@discord.js/voice';
  1. Run node --prof bot.js

  2. Run node --prof-process isolate...log > processed.txt:

 [C++ entry points]:
   ticks    cpp   total   name
    138    1.3%    JS: ~spawnSync node:internal/child_process:1109:19
    138  100.0%      JS: ~spawnSync node:child_process:831:19
    138  100.0%        JS: ~getInfo /discordbot/node_modules/prism-media/src/core/FFmpeg.js:123:17
    138  100.0%          JS: ~canEnableFFmpegOptimizations /discordbot/node_modules/@discordjs/voice/dist/index.js:2234:38
    138  100.0%            JS: ~<anonymous> /discordbot/node_modules/@discordjs/voice/dist/index.js:1:1

Versions

  • discord.js: 14.13.0
  • @discordjs/voice: 0.16.0

Issue priority

Low (slightly annoying)

Which partials do you have configured?

Not applicable

Which gateway intents are you subscribing to?

Not applicable

I have tested this issue on a development release

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions