Skip to content

Make -p (and cluster-stream walkers) fast: cache reads, skip RBin strings - #19

Merged
trufae merged 2 commits into
mainfrom
claude/r2flutter-p-cpu-bottleneck-al2nqc
Jul 7, 2026
Merged

Make -p (and cluster-stream walkers) fast: cache reads, skip RBin strings#19
trufae merged 2 commits into
mainfrom
claude/r2flutter-p-cpu-bottleneck-al2nqc

Conversation

@trufae

@trufae trufae commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

r2flutter -p burned ~100% CPU for several seconds on large libapp.so/App
images. Two bottlenecks were responsible:

  1. read_mem() went through the full radare2 IO stack (banks, caches,
    interval trees, mmap seek/lseek) once per byte, because the cluster
    stream decoders read one byte at a time while walking the whole
    modern_parse_cluster_meta stream twice. read_mem() now serves reads from
    a forward-sliding 1 MiB window cached in DartCtx, collapsing millions of
    IO calls into a handful. The cache is scoped to a single command and
    freed in dart_obf_fini. A request is only served when fully contained in
    the window; a failed windowed refill falls back to an exact read, so
    semantics are unchanged.

  2. The standalone tool let r_core_bin_load run RBin's whole-file string
    scan (the single largest profile entry) even though r2flutter never uses
    RBin's string list. The CLI now sets bin.strings=false before loading.
    The core plugin path is untouched.

On test/bins/android/mafia/libapp.so (14 MB), -p drops from ~2.6s to
~0.05s (~50x) with byte-identical output across all actions; the shared
read cache also speeds up the heavier -x/-z walkers. Full custom
testsuite (35/35) still passes.

Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01RzwE1yCFnmG27vED2CpkR3

claude added 2 commits July 7, 2026 16:52
…ings

r2flutter -p burned ~100% CPU for several seconds on large libapp.so/App
images. Two bottlenecks were responsible:

1. read_mem() went through the full radare2 IO stack (banks, caches,
   interval trees, mmap seek/lseek) once per byte, because the cluster
   stream decoders read one byte at a time while walking the whole
   modern_parse_cluster_meta stream twice. read_mem() now serves reads from
   a forward-sliding 1 MiB window cached in DartCtx, collapsing millions of
   IO calls into a handful. The cache is scoped to a single command and
   freed in dart_obf_fini. A request is only served when fully contained in
   the window; a failed windowed refill falls back to an exact read, so
   semantics are unchanged.

2. The standalone tool let r_core_bin_load run RBin's whole-file string
   scan (the single largest profile entry) even though r2flutter never uses
   RBin's string list. The CLI now sets bin.strings=false before loading.
   The core plugin path is untouched.

On test/bins/android/mafia/libapp.so (14 MB), -p drops from ~2.6s to
~0.05s (~50x) with byte-identical output across all actions; the shared
read cache also speeds up the heavier -x/-z walkers. Full custom
testsuite (35/35) still passes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RzwE1yCFnmG27vED2CpkR3
The help test drifted from the actual program output and failed CI:

- Standalone usage (-h) gained the "(-ii same as -i)" note on -i and a new
  "-ie[jr*], -E[jr*]  Print Dart code entrypoint" line that the EXPECT block
  never picked up.
- The core plugin help lists -h once (grouped with -v/-V), but the EXPECT had
  a duplicate "-h show this help" line in the middle of the alphabetical list,
  in both plugin-help blocks.

Regenerated the expected output to match the current binaries; all three
db/extras tests pass under r2r.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RzwE1yCFnmG27vED2CpkR3
@trufae
trufae merged commit 33588f2 into main Jul 7, 2026
9 checks passed
@trufae
trufae deleted the claude/r2flutter-p-cpu-bottleneck-al2nqc branch July 7, 2026 17:27
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