Skip to content
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

Optimize some poorly performing parts of ASYS. #1658

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Hoikas
Copy link
Member

@Hoikas Hoikas commented Jan 27, 2025

This optimizes the "Soft Update" portion of the audio system update. According to my profiling, with 101 male avatars in an Age (resulting in approximately 31,000 sounds loaded), this function would take 7ms on my Ryzen 9 7900X3D. I have something of an overkill CPU, so this kind of drag in the update loop is unacceptable. The problem is that the sounds are all being stored in an intrusive doubly linked list, which is being traversed and partially bubble sorted each update. This pull request changes the container from the intrusive doubly-linked list to an std::vector and uses std::sort() to sort the active sounds. This change results in the "Soft Update" portion of the update loop only taking about 3ms on my Ryzen 9 7900X3D.

As a bonus, I have improved the semantics around accessing the plSoundBuffer* from plSound objects. There was already a plSoundBuffer* member variable, but it was only ever set by the exporter. The client code was grabbing an active ref and continually grabbing the object pointer from the plKey. I have changed this to store the plSoundBuffer* in the field that already exists, removing the pointless indirection.

@Hoikas Hoikas changed the title Optimize some poorly performaing parts of ASYS. Optimize some poorly performing parts of ASYS. Jan 27, 2025
We already have a member for a pointer to the sound buffer. Let's use it
and avoid chasing down and converting the buffer key's object pointer.
Traversing the linked list with lots of avatars spawned in is much
slower than any copying done to move sounds in the list. Probably due to
all of the cache unfriendly reads and the *gulp* bubble sort.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants