惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
腾讯CDC
博客园 - 司徒正美
A
About on SuperTechFans
H
Help Net Security
J
Java Code Geeks
C
Check Point Blog
B
Blog RSS Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
MongoDB | Blog
MongoDB | Blog
U
Unit 42
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
MyScale Blog
MyScale Blog
V
Visual Studio Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
InfoQ
H
Hackread – Cybersecurity News, Data Breaches, AI and More
F
Fortinet All Blogs
博客园 - 聂微东
酷 壳 – CoolShell
酷 壳 – CoolShell
GbyAI
GbyAI
博客园 - 【当耐特】
雷峰网
雷峰网

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
perf: cache startup package metadata · openclaw/openclaw@...
steipete · 2026-05-02 · via Recent Commits to openclaw:main

@@ -3,26 +3,41 @@ import { fileURLToPath } from "node:url";

33

import { openClawRootFs, openClawRootFsSync } from "./openclaw-root.fs.runtime.js";

4455

const CORE_PACKAGE_NAMES = new Set(["openclaw"]);

6+

const packageNameCache = new Map<string, string | null>();

7+

const packageRootCache = new Map<string, string | null>();

8+

const argv1CandidateCache = new Map<string, string[]>();

69710

function parsePackageName(raw: string): string | null {

811

const parsed = JSON.parse(raw) as { name?: unknown };

912

return typeof parsed.name === "string" ? parsed.name : null;

1013

}

11141215

async function readPackageName(dir: string): Promise<string | null> {

16+

const packageJsonPath = path.join(path.resolve(dir), "package.json");

17+

if (packageNameCache.has(packageJsonPath)) {

18+

return packageNameCache.get(packageJsonPath) ?? null;

19+

}

1320

try {

14-

return parsePackageName(await openClawRootFs.readFile(path.join(dir, "package.json"), "utf-8"));

21+

const name = parsePackageName(await openClawRootFs.readFile(packageJsonPath, "utf-8"));

22+

packageNameCache.set(packageJsonPath, name);

23+

return name;

1524

} catch {

25+

packageNameCache.set(packageJsonPath, null);

1626

return null;

1727

}

1828

}

19292030

function readPackageNameSync(dir: string): string | null {

31+

const packageJsonPath = path.join(path.resolve(dir), "package.json");

32+

if (packageNameCache.has(packageJsonPath)) {

33+

return packageNameCache.get(packageJsonPath) ?? null;

34+

}

2135

try {

22-

return parsePackageName(

23-

openClawRootFsSync.readFileSync(path.join(dir, "package.json"), "utf-8"),

24-

);

36+

const name = parsePackageName(openClawRootFsSync.readFileSync(packageJsonPath, "utf-8"));

37+

packageNameCache.set(packageJsonPath, name);

38+

return name;

2539

} catch {

40+

packageNameCache.set(packageJsonPath, null);

2641

return null;

2742

}

2843

}

@@ -60,6 +75,11 @@ function* iterAncestorDirs(startDir: string, maxDepth: number): Generator<string

6075

}

61766277

function candidateDirsFromArgv1(argv1: string): string[] {

78+

const cacheKey = path.resolve(argv1);

79+

const cached = argv1CandidateCache.get(cacheKey);

80+

if (cached) {

81+

return [...cached];

82+

}

6383

const normalized = path.resolve(argv1);

6484

const candidates = [path.dirname(normalized)];

6585

@@ -81,21 +101,30 @@ function candidateDirsFromArgv1(argv1: string): string[] {

81101

const nodeModulesDir = parts.slice(0, binIndex).join(path.sep);

82102

candidates.push(path.join(nodeModulesDir, binName));

83103

}

84-

return candidates;

104+

const deduped = dedupeCandidates(candidates);

105+

argv1CandidateCache.set(cacheKey, deduped);

106+

return [...deduped];

85107

}

8610887109

export async function resolveOpenClawPackageRoot(opts: {

88110

cwd?: string;

89111

argv1?: string;

90112

moduleUrl?: string;

91113

}): Promise<string | null> {

92-

for (const candidate of buildCandidates(opts)) {

114+

const candidates = buildCandidates(opts);

115+

const cacheKey = createPackageRootCacheKey(candidates);

116+

if (packageRootCache.has(cacheKey)) {

117+

return packageRootCache.get(cacheKey) ?? null;

118+

}

119+

for (const candidate of candidates) {

93120

const found = await findPackageRoot(candidate);

94121

if (found) {

122+

packageRootCache.set(cacheKey, found);

95123

return found;

96124

}

97125

}

98126127+

packageRootCache.set(cacheKey, null);

99128

return null;

100129

}

101130

@@ -104,13 +133,20 @@ export function resolveOpenClawPackageRootSync(opts: {

104133

argv1?: string;

105134

moduleUrl?: string;

106135

}): string | null {

107-

for (const candidate of buildCandidates(opts)) {

136+

const candidates = buildCandidates(opts);

137+

const cacheKey = createPackageRootCacheKey(candidates);

138+

if (packageRootCache.has(cacheKey)) {

139+

return packageRootCache.get(cacheKey) ?? null;

140+

}

141+

for (const candidate of candidates) {

108142

const found = findPackageRootSync(candidate);

109143

if (found) {

144+

packageRootCache.set(cacheKey, found);

110145

return found;

111146

}

112147

}

113148149+

packageRootCache.set(cacheKey, null);

114150

return null;

115151

}

116152

@@ -131,5 +167,31 @@ function buildCandidates(opts: { cwd?: string; argv1?: string; moduleUrl?: strin

131167

candidates.push(opts.cwd);

132168

}

133169134-

return candidates;

170+

return dedupeCandidates(candidates);

171+

}

172+173+

function dedupeCandidates(candidates: readonly string[]): string[] {

174+

const seen = new Set<string>();

175+

const deduped: string[] = [];

176+

for (const candidate of candidates) {

177+

const resolved = path.resolve(candidate);

178+

if (seen.has(resolved)) {

179+

continue;

180+

}

181+

seen.add(resolved);

182+

deduped.push(resolved);

183+

}

184+

return deduped;

185+

}

186+187+

function createPackageRootCacheKey(candidates: readonly string[]): string {

188+

return candidates.join("\0");

135189

}

190+191+

export const __testing = {

192+

clearOpenClawPackageRootCaches(): void {

193+

packageNameCache.clear();

194+

packageRootCache.clear();

195+

argv1CandidateCache.clear();

196+

},

197+

};