Experimental CPU Optimize Techniques
CI / test (push) Successful in 1m1s
Release rolling / release (push) Successful in 7m25s

This commit is contained in:
Raven Scott
2026-07-21 11:58:29 -04:00
parent 58fcc52d6c
commit 1d902a89b0
8 changed files with 149 additions and 68 deletions
+34
View File
@@ -0,0 +1,34 @@
import fs from 'fs'
const READ_BUF = Buffer.alloc(65536)
const fdCache = new Map()
export function readFileCached(path) {
let entry = fdCache.get(path)
if (entry === undefined) {
try {
const fd = fs.openSync(path, 'r')
entry = { fd }
fdCache.set(path, entry)
} catch {
fdCache.set(path, null)
return null
}
}
if (!entry) return null
try {
const bytesRead = fs.readSync(entry.fd, READ_BUF, 0, READ_BUF.length, 0)
return READ_BUF.toString('utf8', 0, bytesRead)
} catch {
return null
}
}
export function closeFdCache() {
for (const [path, entry] of fdCache) {
if (entry) {
try { fs.closeSync(entry.fd) } catch {}
}
}
fdCache.clear()
}