perf: FsStore loads all CAS nodes into memory at startup #85
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
问题
packages/fs/src/store.ts的createFsStore()在启动时调用loadDir()把目录下所有.bin文件全量反序列化(CBOR decode)到内存Map<Hash, CasNode>:之后所有
get()、has()、listAll()都走内存 Map,磁盘文件只在put()和delete()时写入。影响
建议方案
改为按需加载(lazy loading):
get(hash)— 命中内存缓存则返回,否则读文件 + 缓存has(hash)— 检查文件是否存在(existsSync或维护 hash set)listAll()— 读目录文件名(不需要解码 payload)listByType()— 依赖 type index 文件,不需要全量加载关联