Skip to content

perf: replace the per-file cache entries with a compact dir table - #197

Open
benjaminbruun wants to merge 2 commits into
masterfrom
perf/compact-dir-table
Open

benjaminbruun wants to merge 2 commits into
masterfrom
perf/compact-dir-table

Conversation

@benjaminbruun

Copy link
Copy Markdown
Member

Every file cost a 28 B cache entry plus a malloc'd path string although only ten files can hold content at once; an 8 B hashed dir entry plus a fixed slot table cuts the 98-file profile's table from 6.7 KB of heap to 0.8 KB and makes the ten-buffer cap real. Validated on an nRF9151-DK: system-heap peak 13,524 -> 8,640 B, attach unchanged, and a pre-existing provisioned NVS is read as-is. The footprint report will show +160 B RAM (the static slot table); the 4.9 KB heap saving is invisible to it.

@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Firmware footprint delta — nrf9151dk/nrf9151/ns

softsim_external_profile app image, from the ELF program headers (flash = load image incl. initialized data, RAM = static SRAM use incl. .bss/noinit):

Memory base PR Δ
Flash 146.1 KiB 146.8 KiB +708 B
RAM 72.3 KiB 72.5 KiB +160 B
Section size changes (from the section headers)
     +14 B  .strtab              (65698 -> 65712)
    +128 B  .symtab              (82080 -> 82208)
    +160 B  bss                  (20722 -> 20882)
    +132 B  rodata               (34508 -> 34640)
    +580 B  text                 (111776 -> 112356)
Top symbol changes (10 largest, from the symbol tables)
    +288 B  ss_dir_table_from_blob
    +160 B  fs_slots
    +144 B  ss_fopen
    -130 B  generate_dir_table_from_blob
    +120 B  ss_slot_acquire
    -106 B  f_cache_find_buffer
    +100 B  port_provision
     +68 B  ss_dir_find
     +40 B  ss_file_size
     -34 B  f_cache_find_by_name

Soft report — informational only. Base 418e66207ab626f4a312fdcf6d5656eb97d5c712 vs PR head.

@benjaminbruun
benjaminbruun force-pushed the perf/compact-dir-table branch from c3d347b to 3a65b53 Compare August 28, 2026 13:53
Every file cost a 28 B list entry plus a malloc'd path string although only
ten files can hold content at once; an 8 B hashed dir entry plus a fixed
slot table cuts the 98-file profile's table from 6.7 KB of heap to 0.8 KB
and makes the ten-buffer cap real.

Signed-off-by: Benjamin Bruun <bb@onomondo.com>
Signed-off-by: Benjamin Bruun <bb@onomondo.com>
@peterbornerup

Copy link
Copy Markdown
Member

Overall very nice :D

Currently deleting files is half supported (at least the nvs key is removed). Creating files is not supported.

With this hashed approach updating the NVS DIR_ENTRY is gonna be harder as it can't be built from the context in memory. So the whole blob needs to be re-parsed, then updated and then re-written to the entry.

Small price to pay for such a big win memory wise :P

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