Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

mix transition allocates 9.2 MB per instance

Open
#1,316 5 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@iDoMeteor is already working on this.

Since Oct 1, 2026.

  • #1332 by @iDoMeteor — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c

Research direction

Start in transition_mix.c, focusing on the src_buffer and dest_buffer fields and the get_audio path. Reproduce the allocation behavior with the linked 500-transition example, then compare memory and rebuild time after the buffers are changed to reflect actual use. Done means mix transitions no longer reserve and touch 9.2 MB each when that capacity is unnecessary.

Written by the indexing model from the issue text.

Description

Environment: MLT 7.40.0 (Fedora 44 package, x86_64), FFmpeg 8.1.2. The code involved is unchanged on master (0926a75).

Found while building a GTK4 video editor on MLT; the repro below uses only melt/libmlt.

What happens

transition_mix embeds two MAX_SAMPLES * MAX_CHANNELS float buffers (192,000 × 6 × 4 bytes each) in its private struct (transition_mix.c, src_buffer and dest_buffer), so every mix is a 9.2 MB calloc(), whether or not it ever mixes more than a frame's worth of samples.

With glibc this is cheap at first: allocations that big are served by fresh mmap, whose pages are zero and stay untouched. But the first time one is freed, glibc's dynamic mmap threshold rises above 9.2 MB, and from then on each mix comes from the heap and calloc() zeroes all 9.2 MB. An app that rebuilds a graph with many mixes (one per track, plus one per audio crossfade) then pays gigabytes of resident memory and seconds of zeroing per rebuild.

Repro

Create 500 mix transitions, close them, repeat, with one small allocation kept alive per round (as the next graph's objects are): https://github.com/iDoMeteor/u-studio-video-editor/tree/70841c3/tools/upstream-repros/mlt/mix-struct-size

round 1: 500 mix transitions created in 4 ms, RSS while alive 83 MB, after close 81 MB
round 2: 500 mix transitions created in 33 ms, RSS while alive 147 MB, after close 147 MB
round 3: 500 mix transitions created in 2266 ms, RSS while alive 4475 MB, after close 4475 MB
round 4: 500 mix transitions created in 380 ms, RSS while alive 4475 MB, after close 4475 MB

In a real editor with 1,992 crossfades on a long timeline, rebuilds went from 0.35 s to 5.7 s, and resident memory reached 36 GB within nine rebuilds.

Expected: a mix costs what it uses. Actual: 9.2 MB each, fully touched once the heap is reused.

Notes

Allocating the buffers lazily (on the first get_audio), or sizing them to the frames actually mixed, would fix it. We work around it with mallopt(M_MMAP_THRESHOLD, 4 MiB) before mlt_factory_init(), which also turns off glibc's dynamic adjustment.

Dominant language
C
Stars
1.9k
Forks
391
Avg merge
1d 17h
Merged PRs (30d)
12

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mltframework/mlt

All issues in mltframework/mlt

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.