xiMatrix

filter net requests according to source, destination and type  https://addons.mozilla.org/firefox/addon/ximatrix/
git clone https://git.ce9e.org/xiMatrix.git

commit
ba4566615cba9ee6a9d69e16072fea3945b44cfc
parent
f4888c39857066c074c54e7e4dc85616479203c6
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2023-12-08 19:34
cache storage access

I used http://www.raymondhill.net/ublock/pageloadspeed.html
for a simple benchmark:

without cache (all allowed)	3543.45 ms
no extension	3030.00 ms
with cache (all allowed)	2536.27 ms
without cache (all blocked)	782.36 ms
with cache (all blocked	732.91 ms

I am not sure how valid these results are, but it is good enough to give
it a try.

Diffstat

M src/storage.js 19 ++++++++++++++++++-

1 files changed, 18 insertions, 1 deletions


diff --git a/src/storage.js b/src/storage.js

@@ -14,16 +14,25 @@ var STORAGE_AREAS = {
   14    14 };
   15    15 
   16    16 var lock = Promise.resolve();
   -1    17 var cache = {};
   17    18 
   18    -1 export var get = async function(key) {
   -1    19 var _get = async function(key) {
   19    20     var data = await STORAGE_AREAS[key].get(key);
   20    21     return data[key] ?? STORAGE_DEFAULTS[key];
   21    22 };
   22    23 
   -1    24 export var get = function(key) {
   -1    25     if (!cache[key]) {
   -1    26         cache[key] = _get(key);
   -1    27     }
   -1    28     return cache[key];
   -1    29 };
   -1    30 
   23    31 var _change = async function(key, fn) {
   24    32     var oldValue = await get(key);
   25    33     var data = {};
   26    34     data[key] = fn(oldValue);
   -1    35     delete cache[key];
   27    36     await STORAGE_AREAS[key].set(data);
   28    37 };
   29    38 
@@ -32,6 +41,14 @@ export var change = async function(key, fn) {
   32    41     await lock;
   33    42 };
   34    43 
   -1    44 var invalidateCache = function(changes) {
   -1    45   for (var key in changes) {
   -1    46     delete cache[key];
   -1    47   }
   -1    48 };
   -1    49 
   -1    50 browser.storage.local.onChanged.addListener(invalidateCache);
   -1    51 
   35    52 // migrations
   36    53 browser.runtime.onInstalled.addListener(() => {
   37    54     // 0.8.0: store requests to session storage