I have been using a profiler to optimize my game for the Xbox, my aim is as with any optimization to reduce excess CPU and memory usage. I have managed to cut down a lot of the processor time and memory used by my game. However i have a lot of bullets in my game that the player fires and every-time a bullet impacts with something the soundeffect.play() method is called to play the explosion. I would like to know if there is a more efficient way of playing the explosion soundeffect?

  • \$\begingroup\$ Are you sure there is an actual performance problem with .play() for your project? Have you confirmed this, or are you asking into the blue? \$\endgroup\$
    – Hackworth
    Feb 24, 2013 at 12:38
  • \$\begingroup\$ I am asking if anyone thinks there is a more efficient way of playing soundeffects, particularly when i have a large amount of bullets calling the built in method. i.e. has anyone managed to create a more efficient way of doing this? \$\endgroup\$
    – Ree
    Feb 24, 2013 at 13:24

1 Answer 1


You could possibly look into SoundEffectInstance. You can get one with SoundEffect.CreateInstance (and must Dispose of it when you are finished with it).

SoundEffect.Play internally creates SoundEffectInstance objects and plays them. It then adds them to an internal list so that, once that sound effect has finished playing, it is stopped and added back to a pool. The next time you call SoundEffect.Play, it will try and get a spare instance from the pool, before allocating another one.

By using SoundEffectInstance yourself, you can pre-allocate your desired number of instances of a sound, so you don't have the cost of allocation if the pool is empty. And you save the (small) overhead involved in tracking those internal "fire and forget" sound instances.

This can also allow you to limit the number of sounds playing at once (saving CPU). For example, if you create three instances of a sound (in a circular buffer), and your game has a situation where it wants to trigger that sound four times in a row - on the fourth trigger you could either cut off the oldest sound and restart it, or skip playing the new sound.

  • \$\begingroup\$ Thank You Andrew I will try this out, sounds pretty promising. \$\endgroup\$
    – Ree
    Feb 24, 2013 at 13:50
  • \$\begingroup\$ @Ree let us know how this plays out for performance. \$\endgroup\$
    – ashes999
    Feb 24, 2013 at 14:32
  • \$\begingroup\$ No problem, i have some other things i need to sort out at the moment, but will try this out and report back as soon as i am finished, Thanks. \$\endgroup\$
    – Ree
    Feb 24, 2013 at 15:32
  • \$\begingroup\$ Hey Andrew I have tried out your suggestions, i would like to say that i have got some "good" results, however performance wise as you pointed out they are marginal. I have more control over the sound effects and how many can be played max at once. However the extra code needed may not be worth it for some people. It may be my implementation but if i manage to see any significant improvements i will be sure to leave a message here. Thank you for your answer. :) \$\endgroup\$
    – Ree
    Feb 25, 2013 at 22:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .