Skip to content

Parallelize checksum validation#14

Open
hangduykhiem wants to merge 2 commits into
joshuatam:gamenative-latestfrom
hangduykhiem:parallelize-checksum-validation
Open

Parallelize checksum validation#14
hangduykhiem wants to merge 2 commits into
joshuatam:gamenative-latestfrom
hangduykhiem:parallelize-checksum-validation

Conversation

@hangduykhiem

@hangduykhiem hangduykhiem commented Jul 8, 2026

Copy link
Copy Markdown

Description

On GameNative, I get stuck at checksum validation for Borderlands 2 for an hour.

Up on checking, the validateSteam3FileChecksums is doing it 1 thread at at time. So I decided to send a patch.

This PR add Default.IO to parallelize checksum validation. It has a semaphore to keep it never spawning more than availableProcessors or MAX_VALIDATE_CONCURRENCY

Why do we want availableProcessors even if this is running on IO dispatcher with default 64 thread pool instead of Default? We don't want to use Default because we can exhaust the computation during download which isn't nice, so we use I/O. At the same time, you can't usefully run more concurrent Adler32 computations than you have cores. => I actually wonder if this should be documented. Let me know and I'll send another patch.

Checklist

  • Code compiles correctly
  • All tests passing
  • Samples run successfully
  • Extended the README / documentation, if necessary

Chunk verification for a single file was a fully serial for-loop, so
validating a large depot file (thousands of chunks) pegged one CPU
core for a long time while other cores sat idle, causing significant
thermal load on Android devices during file verification.

Fans out chunk reads/Adler32 checks across coroutines on
Dispatchers.IO, bounded by a Semaphore sized to available processors
(capped at 16), so verification throughput scales with device core
count instead of being limited to a single thread.
Relocates MAX_VALIDATE_CONCURRENCY and defaultValidateConcurrency()
next to the other object-level declarations at the top of Util,
matching this repo's convention of declaring constants near the top
of the class instead of inline between functions.

Adds UtilValidateSteam3FileChecksumsTest covering: all-chunks-match,
mismatched-chunk detection, result ordering, correctness across
different concurrency values, and a larger chunk-count smoke test.
No prior test coverage existed for validateSteam3FileChecksums.
@hangduykhiem

hangduykhiem commented Jul 8, 2026

Copy link
Copy Markdown
Author

Logs of successful samples here: logs.txt

Notice that Validating steamapps/... lines all timestamped within the same millisecond (23:39:57.230-.234), so we can say that this runs concurrently.

Hopefully I can download borderlands 2 much faster if this is approved and merged.

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.

1 participant