Skip to content

Renderer engine review (2026-12) ​

Answers the question "can the reader engine be made faster, and how much". Written against devel@d42e4af (v2.5.8) and a fork of the same lineage (Harrys-HQ/ShinKu). Every claim below is either a file/line in this tree or a measurement reproduced by the scripts named at the end.

Short answer: the renderer is not where the remaining time is. The frame budget is already met (ADR 0002 measured P99 overrun going from +0.3 ms to −5.2 ms when LazyColumn was replaced by ComposeSceneRenderer, and per-frame CPU P99 −39 %). What is left is waste in the page-loading path — and, as H3 records, one figure that looks like it should not be the same on every phone but cannot be changed on reasoning alone, because the code already carries the measurement that fixes it.


1 · Why "more Vulkan" is not the answer ​

Loading a page is: download → decode → scale → hand over pixels. None of those is GPU work. Decoding is libjpeg-turbo inside Skia (CPU), scaling a Bitmap is CPU, and the GPU only runs at the end, when Compose composites pixels that are already prepared. The one place Vulkan is used today is the optional super-resolution (RealEsrganNcnnEngine, RealCuganNcnnEngine, Anime4kImageEngine, built against ncnn-*-android-vulkan in app/src/main/cpp/CMakeLists.txt), which is a quality feature that costs time and battery and is off by default (PageLoader.loadPageImpl only runs it when settings.isReaderSuperResolutionEnabled).

Splitting a network between CPU and GPU does not give the sum of both: the synchronisation and the host↔device copies take the gain, and on a phone —shared memory, shared thermal budget— it usually gives less throughput and more heat. The parallelism that is actually unused is between CPU cores, on different pages.

The one exception worth keeping: ncnn already falls back to CPU when no Vulkan device exists (realesrgan_jni.cpp: if (ncnn::get_gpu_count() == 0) gpuid = -1;). That fallback is correct and should stay.

2 · Where the waste is, measured ​

Reproduced here with Pillow/libjpeg-turbo over pages of the kind the app reads (text, screentone, gradients). These are mechanism measurements, not device measurements: the reader decodes in C++ with BitmapRegionDecoder, so absolute milliseconds differ. The ratio between paths is what decides whether an optimisation is worth it.

2.1 Decoding at full size and scaling down afterwards ​

SourceTargetFull decode + resizeDecode at targetGainBitmap
1600×24001080×162061 ms58 ms×1.0615.4 → 7.0 MB
1600×2400720×108050 ms22 ms×2.2715.4 → 3.1 MB
3000×45001080×1620142 ms66 ms×2.1554.0 → 7.0 MB
3000×4500720×1080131 ms28 ms×4.6854.0 → 3.1 MB

The waste grows with page size and shrinks with screen size. ImageDecodeSize.resolve already computes the right size; the open question is whether every path uses it (the tile path does —RegionBitmapDecoder, AndroidRegionDecoderFactory—; the full-page Coil path needs confirming with the phase traces from §3).

2.2 Tiles ​

PageWhole bitmapResident tiles (6 × 256 px)Gain
3000×450054.0 MB1.6 MB×34
1080×16207.0 MB1.6 MB×4.4

Already implemented (ReaderTileManager, TileMemoryBudget). The 8× on memory is here, not in the renderer.

2.3 What the other engine pays for its "upscaling" ​

The ShinKu fork scales each page with a Matrix (bilinear) and then runs a 3×3 unsharp mask on the CPU (UpscalingInterceptor.upscale). Measured: 30 ms to decode, 323 ms with the upscale — +293 ms per page, ×10.7, and it adds no information (bilinear invents pixels, unsharp raises edge contrast). Over 20 pages that is 5.9 s of pure cost, in time, battery and heat.

This is where an energy win actually lives: not in a faster renderer, in not doing optional work by default.

3 · Readiness items ​

H0 · Trace the page path by phase — done in this change ​

ReaderPhaseTrace names the phases and PageLoader opens a section around each: download, prepare, super-resolution, plus the download-permit wait and the whole decode/publish in KototoroImagePipelineAdapter. The reader had traces for tile session teardown and a close lock, but none along the path a page takes, so a slow chapter could not be attributed to the network rather than the decoder.

Sections are no-ops unless tracing is enabled and the device is Q+ (Trace.isEnabled()), matching the pattern ReaderTileManager already used. TraceSectionMetric in :macrobenchmark reads them directly.

Every phase suspends and can resume on another thread, so they are async sections (Trace.beginAsyncSection with a cookie per call), not beginSection/endSection, which must pair on one thread. The permit section ends as soon as the permit is held, so it is the wait alone; Reader.Download contains it (wait + fetch), and the fetch is the download minus the permit.

Checked on a device (2026-12-02, 90 s of paging): every section closed, up to nine Reader.Download sections ran at once without closing each other, and Reader.AcquirePermit read 0–0.1 ms with a free permit and 1.07–1.38 s while queued.

H3 · Size the tile cap to the device — attempted, withdrawn; the constant stands ​

The cap is 256 MB on every device (TileMemoryBudget.DEFAULT_MAX_BYTES). The tempting change is to derive it from the heap the platform grants. It was written, and it does not survive its own reasoning — it is withdrawn here rather than shipped.

What was implemented: cap = clamp(0.12 × javaHeapLimit, 96 MB, 256 MB), wired to ActivityManager.memoryClass, plus a test. Two defects, both fatal:

  1. It cannot act on the devices it was meant to help. 0.12 × a 256 MB heap is 30.7 MB, which is below the 96 MB floor, so the floor wins: a 4 GB phone gets 96 MB, an 8 GB phone (512 MB heap, 61 MB) also gets 96 MB. The heap figure starts to matter only around a 1 GB heap, i.e. large devices, which are exactly the ones that did not need shrinking. The claimed outcome ("~30 MB instead of 256") is arithmetically impossible under the clamp that contains it, and the test asserted that impossible value — so it would have failed on a real runner. It was never green; it was never run.
  2. It moves against the measurement it was quoting. TileMemoryBudget records that the pinned working set at 2× is ~207 MB, and that dropping the cap under it made the ledger churn halo tiles: evictions 50 → 140, decode launches 239 → 624, frame-overrun P99 from −0.8 ms to +95 ms. So the real choice is not "256 MB or a device-sized cap"; it is "≥ 207 MB, or a frame-time regression". A 96 MB cap is below the working set on every device, and on any device whose heap does grant more than 207 MB the 0.12 rule lowers the cap toward it.

The honest conclusion is that the working set, not the heap, is the number that governs, and it is already above the default on the largest pages. That is why the constant stays. What would make this item real is not a formula but a measurement: TileMemoryBudget already reports the resident set, so a capture of pinned bytes vs cap during a zoomed chapter says whether 256 MB is over-provisioned on 4 GB phones in practice. Until that capture exists, changing the cap is guesswork dressed as arithmetic.

The lesson is worth more than the patch: a constant that a code comment justifies with a measured regression is not "hardcoded default to be improved", it is a recorded decision. The only way to overturn it is a measurement that beats its measurement.

H1 · Decode-at-target — already done, no work left ​

Checked rather than assumed. DecodePlanner.plan resolves SampledSingle with a targetSize whenever the page does not fit the renderer at native scale, and KototoroImagePipelineAdapter passes it through DecodePlan.requestedDecodeSize() into ImageRequest.size(...), with a comment on that helper recording the original bug it fixed (a 6000×9000 page becoming a ~216 MB bitmap). Single is only chosen when sampleSize == 1, i.e. when native resolution is the target, so there is no path left that decodes full size for a smaller viewport. The ×2.15-×4.68 table above is therefore an argument for keeping this invariant, not for adding it; KototoroImagePipelineAdapterDecodeSizeTest pins the mapping.

What is missing is not the constraint but the evidence that it holds on device: with H0's sections in place, Reader.DecodeAsset ÷ Reader.Download per page shows it directly, and that comparison cannot be made from source. This is now a measurement task, not a code task.

H2 · Honour the decode plan's allocation verdict — in this PR, with a three-state guard ​

DecodeAllocatorPolicy.resolve(usage, allowHardware) maps DISPLAY_ONLY → HARDWARE and CPU_READ_REQUIRED → SOFTWARE; DecodePlan carries the verdict on every plan; and nothing consumed it. The Coil request set allowHardware(false) only for RGB_565, so the one decision about where the pixels should live was computed per page and discarded. PixelUsage.CPU_READ_REQUIRED is not referenced anywhere in production code, which is the same fact seen from the other side.

The trap when wiring it up: the planner resolves allowHardware = true only when RendererCapabilities is Resolved, and only ComposeScenePagedReader reports it. On the other hosts the planner therefore answers SOFTWARE for every page, and honouring that would move working bitmaps out of GPU memory (Coil's default on API 26+) into the Java heap — the opposite of the goal. So the request applies a tri-state: null when the renderer has not reported its limits (leave Coil alone), and only an explicit SOFTWARE verdict disables hardware bitmaps.

The gap that followed was not in the policy but in the capability report: only ComposeScenePagedReader ever called setRendererCapabilities, so on the horizontal and webtoon hosts the planner answered SOFTWARE for every page and the tri-state correctly declined to act — the verdict existed and was a permanent no-op there. Both hosts now report Canvas.maximumBitmapWidth/Height from the same drawWithContent layer, once per composition, behind a flag, and before the existing graphicsLayer (a drawWithContent after a layer that draws nothing would never run). That is the last piece the policy needed to be able to say HARDWARE where the device allows it.

Honest limit: this cannot be unit-tested — constructing a Compose draw scope and asserting what a canvas reports is not something the test suite can do, which is why the paged host carried it unreported for so long. CI proves it compiles and that the 811 reader tests still pass; only a device capture proves the values arrive.

H4 · Keep optional costs opt-in ​

Super-resolution is already off by default. Remaining: when it is on, its result is written as JPEG quality 92 and cached (ReaderSuperResolutionManager, OUTPUT_QUALITY). Measured on a 3200×4800 result: q92 → 1 558 KB, q85 → 1 294 KB, q80 → 1 162 KB, with encode 54 → 41 ms; that file is cache, re-read on every visit, so it should be tuned for read speed rather than for fidelity that the display scale throws away anyway. Needs a device measurement of the encode→decode loop before changing the number.

H5 · Improvement stages as plugins ​

The shape already exists: a Coil Interceptor (ShinKu uses one) and a pluggable ReaderRenderer (ADR 0002, with ComposeSceneRenderer, AndroidViewSceneView and the isolated feat/webgpu-reader branch). An improvement stage should declare whether it is CPU or GPU, its measured cost per page, and be switchable without restarting. Nothing optional belongs on the default path.

4 · What not to do ​

  • A new engine. ADR 0002 chose the backend with data and ruled out the native Dawn/Vulkan viewport for Android fragmentation cost. Reopening it buys nothing the frame budget needs.
  • CPU + GPU over one network. Not ×2, and on a phone usually slower and hotter.
  • Cutting the tile cap by decree. Documented above: below the working set, P99 gets much worse.
  • Porting the other engine's reader here. That would trade tiles, a byte ledger and the Draw phase for SubsamplingScaleImageView and a CPU unsharp mask.

5 · What has not been measured ​

  • Absolute milliseconds on a device: no adb here. Needs the repo's own macrobenchmark (FrameTimingMetric, MemoryUsageMetric, TraceSectionMetric) on the new sections.
  • Energy: same 72-page sequence ReaderProductionBenchmark uses, with the optional stages on and off.
  • Whether ComposeSceneRenderer draws HARDWARE bitmaps without an internal copy on all supported Android versions — plausible, unverified; check with a trace before extending it.
  • The cost per page of the GPU super-resolution on a specific phone, which is the figure that decides whether it should stay a plugin or be dropped.

6 · Reproducing the numbers ​

The measurements come from three scripts: page synthesis, draft()-versus-full-decode, and the ShinKu upscale reproduction. They are self-contained (Pillow + numpy) and their results are the tables above.

Documentation for Kototoro