gh-10649: Implement JSON store length hints (gh-13260)

This commit is contained in:
mr. m
2026-04-15 18:59:40 +02:00
committed by GitHub
parent c128b79723
commit b988f23a14
7 changed files with 667 additions and 20 deletions

View File

@@ -0,0 +1,29 @@
diff --git a/toolkit/modules/JSONFile.sys.mjs b/toolkit/modules/JSONFile.sys.mjs
index 397991e4af8f49b6365d729fc11267b5c1113400..1955b7ff1d428e891f5ef066e7a4ac25aa5ec9b4 100644
--- a/toolkit/modules/JSONFile.sys.mjs
+++ b/toolkit/modules/JSONFile.sys.mjs
@@ -132,6 +132,7 @@ export function JSONFile(config) {
this._finalizeInternalBound,
() => ({ sanitizedBasename: this.sanitizedBasename })
);
+ this._useSizeHints = config.useSizeHints ?? false;
}
JSONFile.prototype = {
@@ -423,11 +424,15 @@ JSONFile.prototype = {
}
try {
- await IOUtils.writeJSON(
+ if (this._useSizeHints && this._lastSavedSize) {
+ this._options.lengthHint = this._lastSavedSize;
+ }
+ const result = await IOUtils.writeJSON(
this.path,
this._data,
Object.assign({ tmpPath: this.path + ".tmp" }, this._options)
);
+ this._lastSavedSize = this._useSizeHints ? result.jsonLength : null;
} catch (ex) {
if (typeof this._data.toJSONSafe == "function") {
// If serialization fails, try fallback safe JSON converter.