# Importing audioSceneComponent causes massive increase in memory usage

**URL:** <https://forum.babylonjs.com/t/importing-audioscenecomponent-causes-massive-increase-in-memory-usage/52410>\
**Category:** Questions\
**Tags:** audio\
**Created:** [July 29, 2024, 10:44pm UTC](https://forum.babylonjs.com/t/importing-audioscenecomponent-causes-massive-increase-in-memory-usage/52410 "2024-07-29T22:44:24Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![alekop](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/alekop/32/4380_2.png) [@alekop](https://forum.babylonjs.com/u/alekop)\
**Post date:** [July 29, 2024, 10:44pm UTC](https://forum.babylonjs.com/t/importing-audioscenecomponent-causes-massive-increase-in-memory-usage/52410/1 "2024-07-29T22:44:24Z")

</div>

`import "@babylonjs/core/Audio/audioSceneComponent";` causes my app’s memory usage to go from about 180MB to over 1GB. Tested in Chrome (macOS), Safari (macOS), Safari (iOS).

There’s no issue in playgrounds, but I’m not sure how to replicate it in a playground, because there’s no direct control over imports.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [July 29, 2024, 11:22pm UTC](https://forum.babylonjs.com/t/importing-audioscenecomponent-causes-massive-increase-in-memory-usage/52410/2 "2024-07-29T23:22:07Z")

</div>

cc @docEdub

---

<div class="post-metadata">

**Author:** ![docEdub](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/docedub/32/14525_2.png) [@docEdub](https://forum.babylonjs.com/u/docEdub)\
**Post date:** [July 30, 2024, 3:14pm UTC](https://forum.babylonjs.com/t/importing-audioscenecomponent-causes-massive-increase-in-memory-usage/52410/3 "2024-07-30T15:14:31Z")

</div>

On macOS Safari using a barebones webpack-based app.ts I’m only seeing a 35 MB memory increase when adding `import "@babylonjs/core/Audio/audioSceneComponent";`

Can you tell us more about your setup? Are you using Webpack? Something else? Can we see the code, or can you repro it in a public github repo?

---

<div class="post-metadata">

**Author:** ![alekop](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/alekop/32/4380_2.png) [@alekop](https://forum.babylonjs.com/u/alekop)\
**Post date:** [July 30, 2024, 11:55pm UTC](https://forum.babylonjs.com/t/importing-audioscenecomponent-causes-massive-increase-in-memory-usage/52410/4 "2024-07-30T23:55:47Z")

</div>

You’re right, the audio component is not a problem. The issue seems to be a specific large mp3 file (10MB). I swapped it with a different, smaller file, and the memory issues went away.

But… I would still like to know how a 10MB file causes a ~750MB spike memory usage, and only in BJS apps. Interestingly, playing the same mp3 in a Chrome tab (by dragging) only costs 35MB.

---

<div class="post-metadata">

**Author:** ![roland](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/roland/32/38940_2.png) [@roland](https://forum.babylonjs.com/u/roland)\
**Post date:** [July 31, 2024, 3:34am UTC](https://forum.babylonjs.com/t/importing-audioscenecomponent-causes-massive-increase-in-memory-usage/52410/5 "2024-07-31T03:34:39Z")

</div>

> [@alekop](#):
>
> The issue seems to be a specific large mp3 file (10MB).

Could you share that specific mp3 so we can do some tests?

---

<div class="post-metadata">

**Author:** ![alekop](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/alekop/32/4380_2.png) [@alekop](https://forum.babylonjs.com/u/alekop)\
**Post date:** [August 5, 2024, 11:58pm UTC](https://forum.babylonjs.com/t/importing-audioscenecomponent-causes-massive-increase-in-memory-usage/52410/6 "2024-08-05T23:58:40Z")

</div>

Sorry about the delay, got busy with other tasks.

I’d post a link, but I don’t remember where I downloaded it. Here are the parts (It’s too big to upload as a single file.)

[ocean.mp3aa.zip](https://forum.babylonjs.com/uploads/short-url/Ag5TJNDn12OWIoiEgKLlU9kqvEb.zip) (5 MB)  
[ocean.mp3ab.zip](https://forum.babylonjs.com/uploads/short-url/zC1FtUIJEY3hnqRMAK7bbf8pciY.zip) (5.0 MB)

To combine, download, remove .zip extension (UI won’t let me upload arbitrary extensions), then run `cat ocean.mp3aa ocean.mp3ab > ocean.mp3`.

---

<div class="post-metadata">

**Author:** ![docEdub](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/docedub/32/14525_2.png) [@docEdub](https://forum.babylonjs.com/u/docEdub)\
**Post date:** [August 6, 2024, 1:52am UTC](https://forum.babylonjs.com/t/importing-audioscenecomponent-causes-massive-increase-in-memory-usage/52410/7 "2024-08-06T01:52:03Z")

</div>

The .mp3 file you’re using is over an hour long. That’s why it’s blowing up the memory usage. The browser is decompressing it and filling a huge memory buffer of uncompressed 32 bit PCM wave data from it. Is there a reason you need it to be that long? A well-crafted one or two minute loop should be fine for an ocean sound.

---

<div class="post-metadata">

**Author:** ![alekop](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/alekop/32/4380_2.png) [@alekop](https://forum.babylonjs.com/u/alekop)\
**Post date:** [August 6, 2024, 2:36am UTC](https://forum.babylonjs.com/t/importing-audioscenecomponent-causes-massive-increase-in-memory-usage/52410/8 "2024-08-06T02:36:37Z")

</div>

No, there’s no good reason at all… I just grabbed something as a placeholder.  
But that file takes only ~35MB when playing in a browser tab by itself. Why does it take up so much more in BJS?

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [August 6, 2024, 2:57am UTC](https://forum.babylonjs.com/t/importing-audioscenecomponent-causes-massive-increase-in-memory-usage/52410/9 "2024-08-06T02:57:16Z")

</div>

With Web Audio API, to use a compressed audio file you must load the compressed audio file into memory and then use `decodeAudioData` to convert the compressed file to an `AudioBuffer` , consisting of float arrays internally—essentially PCM. While it is done automatically it is quite memory intensive.

---

<div class="post-metadata">

**Author:** ![docEdub](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/docedub/32/14525_2.png) [@docEdub](https://forum.babylonjs.com/u/docEdub)\
**Post date:** [August 6, 2024, 4:28am UTC](https://forum.babylonjs.com/t/importing-audioscenecomponent-causes-massive-increase-in-memory-usage/52410/10 "2024-08-06T04:28:37Z")

</div>

When playing it in a browser tab by itself, the .mp3 is being streamed as-is without being decompressed and stored in an uncompressed PCM buffer. You can try using the `streaming` option in the `Sound` constructor to get similar results as the browser, but .mp3’s and streaming audio files have issues with looping back to the beginning cleanly, and I don’t think the `streaming` option works in Safari, so I think your best option is to edit that .mp3 down to a minute or two long and keep using the `Sound` constructor without the `streaming` option.
