dsh-mnemon-source-runtime 0.5.11 → 0.5.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +23 -14
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -267,12 +267,14 @@ function prepareMutation(before, request, now) {
|
|
|
267
267
|
}
|
|
268
268
|
function compactionCandidates(compacted, existing, target, now) {
|
|
269
269
|
const seen = /* @__PURE__ */ new Set();
|
|
270
|
+
const existingByContent = /* @__PURE__ */ new Map();
|
|
271
|
+
for (const entry of existing) if (!existingByContent.has(entry.content)) existingByContent.set(entry.content, entry);
|
|
270
272
|
return compacted.map((entry) => {
|
|
271
273
|
const content = normalizeContent(entry.content, "compacted content");
|
|
272
274
|
if (!isImportance(entry.importance)) throw new Error("compacted importance must be critical, normal, or low");
|
|
273
275
|
if (seen.has(content)) throw new Error("compacted runtime memory contains duplicate entries");
|
|
274
276
|
seen.add(content);
|
|
275
|
-
const unchanged =
|
|
277
|
+
const unchanged = existingByContent.get(content);
|
|
276
278
|
const inheritedBranches = entry.branches ?? unchanged?.branches;
|
|
277
279
|
return {
|
|
278
280
|
content,
|
|
@@ -285,21 +287,28 @@ function compactionCandidates(compacted, existing, target, now) {
|
|
|
285
287
|
});
|
|
286
288
|
}
|
|
287
289
|
function packCompactionCandidates(replacements, target, maxBytes) {
|
|
288
|
-
const
|
|
289
|
-
critical:
|
|
290
|
-
normal:
|
|
291
|
-
low:
|
|
290
|
+
const ranked = {
|
|
291
|
+
critical: [],
|
|
292
|
+
normal: [],
|
|
293
|
+
low: []
|
|
292
294
|
};
|
|
293
|
-
|
|
294
|
-
entry,
|
|
295
|
-
index
|
|
296
|
-
})).sort((left, right) => priority[left.entry.importance] - priority[right.entry.importance] || left.index - right.index);
|
|
295
|
+
replacements.forEach((entry, index) => ranked[entry.importance].push(index));
|
|
297
296
|
const selected = /* @__PURE__ */ new Set();
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
297
|
+
const delimiterBytes = Buffer.byteLength(RUNTIME_ENTRY_DELIMITER, "utf8");
|
|
298
|
+
let used = 0;
|
|
299
|
+
let count = 0;
|
|
300
|
+
for (const importance of [
|
|
301
|
+
"critical",
|
|
302
|
+
"normal",
|
|
303
|
+
"low"
|
|
304
|
+
]) for (const index of ranked[importance]) {
|
|
305
|
+
const entry = replacements[index];
|
|
306
|
+
const matchesTarget = entry.target === target;
|
|
307
|
+
const added = matchesTarget ? Buffer.byteLength(entry.content, "utf8") + (count === 0 ? 0 : delimiterBytes) : 0;
|
|
308
|
+
if (used + added > maxBytes) continue;
|
|
309
|
+
used += added;
|
|
310
|
+
if (matchesTarget) count += 1;
|
|
311
|
+
selected.add(index);
|
|
303
312
|
}
|
|
304
313
|
return replacements.filter((_, index) => selected.has(index));
|
|
305
314
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mnemon-source-runtime",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.12",
|
|
4
4
|
"description": "Self-contained runtime Source for Composable View Memory.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@types/node": "^22.0.0",
|
|
61
61
|
"@types/react": "^18.3.0",
|
|
62
62
|
"@types/react-dom": "^18.3.0",
|
|
63
|
-
"dsh-mnemon": "^0.5.
|
|
63
|
+
"dsh-mnemon": "^0.5.23",
|
|
64
64
|
"jsdom": "^26.0.0",
|
|
65
65
|
"react": "^18.2.0",
|
|
66
66
|
"react-dom": "^18.2.0",
|