Commit Graph
13 Commits
Author SHA1 Message Date
LibretroAdmin 1d1f27a025 config_file: audit and rework — zero-copy pooled parsing (−63% load, −48% write, −99.8% heap ops), injectable file I/O, streaming API, autoconfig profile index (437 opens → 2), 5 pre-existing bugs fixed, fuzzing + regression tests in CI (#19305) 2026-07-30 08:47:22 +02:00
LibretroAdmin 0672da96d6 rhmap/config_file: let a map borrow its string keys
Every RHMAP_*_STR insert stores a private strdup() of the key. For
config_file that copy is pure overhead: the key handed to the map is
always the 'key' field of a struct config_entry_list that the config
file itself owns and that outlives the map at every site --
config_file_deinitialize tears the entry list down after the map,
config_unset removes the map slot before freeing the key, and both
config_file_add_child_list and config_append_file pilfer the donor's
entries before freeing the donor.

Add an opt-in RHMAP_BORROW_KEYS(map) that flips a per-map flag, so
inserts store the caller's pointer and teardown leaves it alone. The
flag lives in the header and is only read on insert, delete and free,
so the lookup path is untouched. Default behaviour is unchanged for
every existing user.

nested_list is the one other string-keyed user in tree and it was
keying off the caller's transient token rather than the copy it had
just made one line above. That is correct today only because the map
duplicates the key; make it key off its own copy so the call site is
right regardless, and bail cleanly if that copy failed to allocate
instead of hashing a NULL key.

Measured on a 1700-entry retroarch.cfg, load plus one
config_get_array() per key, 100 iterations, 5 runs each:

  before   63.2 - 64.6 ms  (mean 63.8)
  after    52.8 - 54.9 ms  (mean 54.0)   -15.4%

cachegrind (--D1=49152,12,64 --LL=1048576,16,64):

  D1 misses  124,714 -> 82,556   -34%
  D refs     5.62M   -> 4.53M    -19%
  Ir         14.67M  -> 11.8M    -20%

Allocation count for the same workload drops from 13,671 to 10,271,
exactly two per key. Identical lookup hit counts before and after;
valgrind reports no leaks and no errors.

Before this change 57% of D1 read misses on a config load were inside
malloc/free rather than in config code at all.
2026-07-27 09:13:38 +02:00
libretroadmin afc9cb509a CXX_BUILDFIX buildfixes 2024-07-20 19:42:45 +02:00
libretroadmin 60e0dd839a iC comments 2024-07-20 17:54:44 +02:00
libretroadmin 7c6054573e (rhmap) use custom strdup 2024-07-06 00:00:29 +02:00
libretroadmin 57c790646f Buildfix 2024-06-29 03:48:50 +02:00
libretroadmin 47ec7c0782 Try to avoid strdup to avoid portability issues 2024-06-29 03:46:06 +02:00
libretroadmin 40c889b562 Add header include for rhmap.h 2024-06-29 03:25:33 +02:00
Bernhard Schelling 780fdf721e Fix possible hash map corruption when deleting string keys 2022-03-21 15:07:53 +01:00
jdgleaver b1a7d3e995 (config_file) Modify hash map usage for proper compatibility with updated RHMAP implementation 2021-04-28 17:34:24 +01:00
Alcaro 2c5c4647e3 Track the complete string in rhmap 2021-04-28 16:09:45 +02:00
Daniel De Matteis 59952c520b (Mac) Silence more warnings 2021-01-26 20:39:36 +01:00
Bernhard Schelling 9bea4831d7 Add 32-bit key hash map rhmap
Based on ex_hashmap32 in menu_explore.c, modify that to use the new rhmap
2021-01-03 00:52:25 +09:00