Skip to content

Refactor: AudioListener reduce object allocations #2501

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

capdevon
Copy link
Contributor

@capdevon capdevon commented Jun 17, 2025

Reduce object allocations when ALAudioRenderer update listener each time the Camera is moved:

This pull request refactors the Listener class in the jMonkeyEngine audio system. The main changes include initializing the location, velocity, and rotation fields at declaration instead of in the constructor, removing redundant constructor assignments, and introducing reusable Vector3f instances (left, up, direction) for direction calculations.

Methods that return direction vectors now store results in these fields rather than creating new objects, improving memory efficiency and reducing unnecessary allocations. Overall, the changes streamline object management and optimize performance in the Listener class.

https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-core/src/main/java/com/jme3/audio/openal/ALAudioRenderer.java#L768

    private void applyListenerRotation(Listener listener) {
        Vector3f dir = listener.getDirection(); // <--
        Vector3f up = listener.getUp(); // <--
        // Use the shared FloatBuffer fb
        fb.rewind();
        fb.put(dir.x).put(dir.y).put(dir.z);
        fb.put(up.x).put(up.y).put(up.z);
        fb.flip();
        al.alListener(AL_ORIENTATION, fb);
    }

@yaRnMcDonuts yaRnMcDonuts added this to the v3.9.0 milestone Jun 19, 2025
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