Skip to content

pylibfdt: Grow the FdtSw buffer geometrically - #189

Merged
dgibson merged 1 commit into
dgibson:mainfrom
flipperdevices:pylibfdt-geo-growth
Aug 8, 2026
Merged

pylibfdt: Grow the FdtSw buffer geometrically#189
dgibson merged 1 commit into
dgibson:mainfrom
flipperdevices:pylibfdt-geo-growth

Conversation

@alchark

@alchark alchark commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Every expansion copies the whole tree into a freshly allocated buffer, so growing by a fixed amount makes building a tree cost time quadratic in its size. This is especially painful when assembling larger images with the data inline, such as U-Boot's binman does for FIT images.

Grow by at least as much as the tree already holds, which is what variable sized arrays usually do specifically to avoid such excessive copying.

With this change, building a Rockchip TF-A+Falcon image whose FIT carries a 31 MiB kernel takes 33.1 s rather than 44.4 s, with binman itself down from 25.3 s to 14.0 s, as 7139 reallocations become 187. The images produced are byte-identical.

Every expansion copies the whole tree into a freshly allocated buffer, so
growing by a fixed amount makes building a tree cost time quadratic in
its size. This is especially painful when assembling larger images with
the data inline, such as U-Boot's binman does for FIT images.

Grow by at least as much as the tree already holds, which is what variable
sized arrays usually do specifically to avoid such excessive copying.

With this change, building a Rockchip TF-A+Falcon image whose FIT carries
a 31 MiB kernel takes 33.1 s rather than 44.4 s, with binman itself down
from 25.3 s to 14.0 s, as 7139 reallocations become 187. The images
produced are byte-identical.

Signed-off-by: Alexey Charkov <alchark@flipper.net>
@dgibson

dgibson commented Aug 8, 2026

Copy link
Copy Markdown
Owner

I had a momentary misgiving about this: for some very constrained environments where libfdt is used, growing the buffer geometrically might consume too much memory. But.. for those environments would not be where pylibfdt is used.

So, merged, thanks.

@dgibson dgibson closed this Aug 8, 2026
@dgibson dgibson reopened this Aug 8, 2026
@dgibson
dgibson merged commit 0748c38 into dgibson:main Aug 8, 2026
35 of 36 checks passed
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