Skip to content

Cut startup time by batching hook setup - #31

Merged
Belonit merged 6 commits into
Phobos-developers:masterfrom
11EJDE11:perf/fast-hook-setup
Oct 29, 2026
Merged

Belonit merged 6 commits into
Phobos-developers:masterfrom
11EJDE11:perf/fast-hook-setup

Conversation

@11EJDE11

Copy link
Copy Markdown

For each of the ~3k hooks (Ares, Phobos, spawner) it calls LoadLibrary/GetProcAddress inside the game through a breakpoint and a single step, then allocates, writes and protects memory separately for each hook site.

Changes

  • Each hook DLL is loaded into the game once. The loader stub also stores the module's base address.
  • Hook and feature-flag addresses are read from the DLLs' export tables on disk, after checking that the loaded module is the same file. Forwarded exports, or a module that doesn't match, fall back to GetProcAddress in the game.
  • All caller code goes in one allocation, written once, then made PAGE_EXECUTE_READ.
  • Nearby hook sites are patched with one read and one write per memory region through PatchCode, in the same order as before.

Results

Time from Syringe start to the game window:

Before After
Desktop: window ~0.95 s ~0.2 s
Desktop: Syringe CPU ~520 ms ~55 ms
Laptop: window ~13 s ~0.9 s
Laptop: Syringe CPU ~10 s ~0.34 s

Single-page allocations in the game drop from 2,700 to 15, and the largest free address range grows from 1,221 MB to 1,389 MB.

Testing

  • All 2,685 hook sites compared in a running game: identical except for bytes that depend on the allocation address. All jump targets match.
  • All hook handlers are PAGE_EXECUTE_READ.
  • A 200k-frame multiplayer replay ran with no CRC mismatches.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Nightly build for this pull request:

This comment is automatic and is meant to allow guests to get latest nightly builds for this pull request without registering. It is updated on every successful build.

@Belonit
Belonit requested review from Belonit and ZivDero October 20, 2026 22:06
Read export tables from the loaded target image instead of trusting on-disk
headers as proof of module identity. Treat zero RVAs as missing exports and
fall back to GetProcAddress for forwarded exports or unreadable tables.
Remove the unused disk export parser and module identity cache.
Check loader exchange, feature flag, memory query and hook transfer results.
Log the failed operation, address, size and captured error code before
throwing. Keep optional export-table reads eligible for fallback.
Split reads and writes for hook groups at each memory region boundary.
Keep overlapping sites together across boundaries so later hooks observe
the bytes produced by earlier hooks.
Retain prepared site patches until the entire caller block is uploaded
and protected as executable. Publish the jumps only after preparation
succeeds, preserving per-region patch transfers.
Check aggregate caller allocation arithmetic against DWORD and vector
limits. Verify each relocated instruction sequence fits its caller slot
with room for the final jump back before copying it.

@Belonit Belonit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve added a few adjustments for edge cases that are easy to miss in a normal game run. DLLs can change their exports in DllMain, and nearby hooks can cross memory-region boundaries, so resolving addresses from disk or combining writes can cause problems.
Since callers now share one allocation, a size miscalculation could also corrupt another hook. The extra checks stop setup and log failures, and jumps are only installed once the caller code is ready to execute.

Otherwise, everything looks good. Great job!

@Belonit
Belonit requested a review from Starkku October 28, 2026 19:20
@Belonit
Belonit merged commit 67b5bb7 into Phobos-developers:master Oct 29, 2026
2 checks passed
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