Bug 1925475 - move browser.ml.modelCacheMaxSizeBytes to GiBs instead of Bytes r=atossou

Differential Revision: https://phabricator.services.mozilla.com/D227327
This commit is contained in:
Tarek Ziadé 2024-10-31 16:42:30 +00:00
parent 9615ca2956
commit eb1b6d6e70
2 changed files with 10 additions and 8 deletions

View File

@ -3770,8 +3770,8 @@ pref("browser.ml.logLevel", "Error");
pref("browser.ml.modelHubRootUrl", "https://model-hub.mozilla.org/");
// Model URL template
pref("browser.ml.modelHubUrlTemplate", "{model}/{revision}");
// Maximum disk size for ML model cache (in bytes)
pref("browser.ml.modelCacheMaxSizeBytes", 1073741824);
// Maximum disk size for ML model cache (in GiB)
pref("browser.ml.modelCacheMaxSize", 4);
// Model cache timeout in ms
pref("browser.ml.modelCacheTimeout", 120000);
// Minimal Physical RAM required in GiB

View File

@ -50,9 +50,11 @@ const DEFAULT_PRINCIPAL_ORIGIN = null;
XPCOMUtils.defineLazyPreferenceGetter(
lazy,
"DEFAULT_MAX_CACHE_SIZE",
"browser.ml.modelCacheMaxSizeBytes"
"browser.ml.modelCacheMaxSize"
);
const ONE_GIB = 1024 * 1024 * 1024;
/**
* Checks if a given URL string corresponds to an allowed hub.
*
@ -164,7 +166,7 @@ export class IndexedDBCache {
},
};
/**
* Maximum size of the cache in bytes. Defaults to "browser.ml.modelCacheMaxSizeBytes".
* Maximum size of the cache in GiB. Defaults to "browser.ml.modelCacheMaxSize".
*
* @type {number}
*/
@ -177,7 +179,7 @@ export class IndexedDBCache {
* @param {object} config
* @param {string} config.dbName - The name of the database file.
* @param {number} config.version - The version number of the database.
* @param {number} config.maxSize Maximum size of the cache in bytes. Defaults to "browser.ml.modelCacheMaxSizeBytes".
* @param {number} config.maxSize Maximum size of the cache in GiB. Defaults to "browser.ml.modelCacheMaxSize".
*/
constructor({
dbName = "modelFiles",
@ -198,7 +200,7 @@ export class IndexedDBCache {
* @param {object} config
* @param {string} [config.dbName="modelFiles"] - The name of the database.
* @param {number} [config.version] - The version number of the database.
* @param {number} config.maxSize Maximum size of the cache in bytes. Defaults to "browser.ml.modelCacheMaxSizeBytes".
* @param {number} config.maxSize Maximum size of the cache in bytes. Defaults to "browser.ml.modelCacheMaxSize".
* @returns {Promise<IndexedDBCache>} An initialized instance of IndexedDBCache.
*/
static async init({
@ -669,8 +671,8 @@ export class IndexedDBCache {
DEFAULT_PRINCIPAL_ORIGIN
);
if (totalSize + fileSize > this.#maxSize) {
throw new Error(`Exceeding cache size limit of ${this.#maxSize} bytes"`);
if (totalSize + fileSize > this.#maxSize * ONE_GIB) {
throw new Error(`Exceeding cache size limit of ${this.#maxSize}GiB"`);
}
const fileEntry = { id: cacheKey, data };