mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-19 15:09:58 -04:00
Add heap_lazy (off by default): on Windows the game's heap is committed where it is first used.
Windows charges every committed page to the commit limit whether it is used or not, and the game sizes its whole heap up front: in Castle Town after Hyrule Field the heap held 6.8 GiB of commit of which 3.4 GiB had ever been used. With heap_lazy = 1 a change of the heap's size only moves its end, an access to a reserved heap page commits the reserved runs of the 64 KiB around it in the access-fault hook and runs again, and the paths that do not fault commit their range first: mem_thaw (file reads, the host-pointer import), mem_kernel_access (file writes, the frame-rate fix's read) and mem_host_readable (the host's pointer checks). A page another path committed is left as it is, so a frozen, probed or armed page keeps its protection. With trace = perf a line per window gives the faults, the bytes committed and the time they took. The contributor's runs on a 16 GB PC: 4.67 instead of 6.77 GiB of heap committed and 29.3 instead of 32.9 GiB of process commit in Castle Town, no "system commit low", 12,858 faults in 440 ms over four minutes, the longest 41 ms. With the setting off nothing is hooked and the heap is committed as before. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -298,7 +298,12 @@ static int probe = -1;
|
||||
static float last_pos[3];
|
||||
static uint64_t last_pos_ns;
|
||||
|
||||
static int read_guest(uint64_t a, void *out, size_t n) { return a && plat_mem_read(a, out, n); }
|
||||
// plat_mem_read copies through the kernel, which fails on a heap page NX2NAVI_HEAP_LAZY has not committed yet
|
||||
static int read_guest(uint64_t a, void *out, size_t n) {
|
||||
if (!a) return 0;
|
||||
mem_kernel_access(a, n);
|
||||
return plat_mem_read(a, out, n);
|
||||
}
|
||||
static uint64_t read_ptr(uint64_t a) {
|
||||
uint64_t p = 0;
|
||||
return read_guest(a, &p, 8) ? p : 0;
|
||||
@@ -447,7 +452,7 @@ static void ocarina_step_write(double dt) {
|
||||
return;
|
||||
}
|
||||
uint64_t slot = read_ptr(MOD_MAIN_BASE + 0x4c7e890), mgr = slot ? read_ptr(slot) : 0;
|
||||
if (!mgr || !plat_mem_readable(mgr + 0x1c0, 4)) return;
|
||||
if (!mgr || !mem_host_readable(mgr + 0x1c0, 4)) return;
|
||||
_Atomic uint32_t *word = (_Atomic uint32_t *)(uintptr_t)(mgr + 0x1c0);
|
||||
uint32_t now_bits = atomic_load_explicit(word, memory_order_relaxed);
|
||||
float now_v;
|
||||
|
||||
Reference in New Issue
Block a user