Skip to content

[BUG]:PCM16 recorder causes very frequent GC on Android 16 devices #1204

@Haotian9850

Description

@Haotian9850

Flutter Sound Version :

  • FULL or LITE flavor ?

  • Important: Result of the command : flutter pub deps | grep flutter_sound

flutter pub deps | grep flutter_sound
├── flutter_sound 9.12.0
│   ├── flutter_sound_platform_interface 9.12.0
│   ├── flutter_sound_web 9.12.0
│   │   ├── flutter_sound_platform_interface...

Severity

  • Crash ? Not a crash

  • Result is not what expected ? This is a performance related issue. High GC is causing app jitter / brief pause

  • Cannot build my App ? This is not a build related issue

  • Minor issue ? This issue was reproducible on all Android 16 devices I tested on (Google Pixel 9a, Samsung Galaxy S25, Xiaomi 15 Ultra)


Platforms you faced the error

  • Android, specifically Android 16

Describe the bug
A clear and concise description of what the bug is.

When a raw PCM16 recorder is opened with the following code,

      await _recorder!.startRecorder(
        codec: Codec.pcm16,
        toStream: _recordingDataController.sink,
        audioSource: AudioSource.microphone,
        sampleRate: 16000,
        numChannels: 1
      );

I can see very frequent GC (multiple times per seconds) which causes lots of app jitter:

In flutter console:

...
WaitForGcToComplete blocked Alloc on Background for 43.228ms
Waiting for a blocking GC Alloc
Background concurrent mark compact GC freed 507MB AllocSpace bytes, 0(0B) LOS objects, 85% free, 4204KB/28MB, paused 199us,1.400ms total 478.542ms
WaitForGcToComplete blocked Alloc on Background for 44.702ms
Waiting for a blocking GC Alloc
Background concurrent mark compact GC freed 507MB AllocSpace bytes, 0(0B) LOS objects, 85% free, 4212KB/28MB, paused 199us,1.473ms total 431.173ms
WaitForGcToComplete blocked Alloc on Background for 37.981ms
Waiting for a blocking GC Alloc
Background concurrent mark compact GC freed 507MB AllocSpace bytes, 0(0B) LOS objects, 85% free, 4204KB/28MB, paused 182us,1.491ms total 444.374ms
WaitForGcToComplete blocked Alloc on Background for 44.484ms
...

And the recorder is causing constant spike of Java memory when profiled in Android Studio (please see the attached screenshot, I can provide a heap dump if it helps):

Image ^when recorder is started, java memory spikes start to appear

Image ^please note the byte[] that is constantly being allocated

To Reproduce
Open a raw PCM 16 recorder on an Android 16 device and observe the GC logs. The recorder still functions, but frequent GC causes app jitter

Findings
I see lots of small byte[] allocated in the heap dump, but the number of allocations doesn't differ too much when testing on Android 16 devices vs. other Android versions. So I am not sure if that was the culprit of the memory spikes & frequent GC. So far, this seems to only occur on Android 16.

Thanks in advance!

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