Comparing version
10
cache.ts
@@ -67,3 +67,11 @@ import { max, min } from './alias'; | ||
文字列やオブジェクトなどからアドレスを取得または代替値を高速に割り当てる方法がなく汎用的に使用できない。 | ||
乱数で代用する方法は強引で低速だがリモートアクセスなど低速な処理では償却可能と思われる。 | ||
またポインタのアドレスを使用する場合もアドレスの再利用により偽陽性および偽陰性が生じヒット率が低下する | ||
可能性がありどのような状況でどの程度低下するかは未知数。 | ||
OSや言語のメモリ割り当て方法によってはメモリアドレスの頻繁な再利用によりヒット率が著しく低下する可能性 | ||
があり信頼性が低い。 | ||
ベンチマークに使用されているブロックアクセスにおいても書き込み範囲のアドレスにおいて同じ問題が生じる | ||
はずでありブルームフィルタから減算するとしないとにかかわらず精度が低下するが公式実装であるCaffeine | ||
においてもこの精度低下が生じない方法で測定(書き込み範囲はキャッシュに追加または無効化されなければ | ||
ならないはずだが単に処理が省略されている)されているため書き込みを含むワークロードの公表されている | ||
ヒット率は誤った測定方法による不正確なものである疑いがある。 | ||
オーバーヘッドが大きくメモ化など同期処理に耐える速度を要件とする用途には適さないと思われる。 | ||
@@ -70,0 +78,0 @@ ブルームフィルタが削除操作不可であるため一定期間内のキャッシュの任意または有効期限超過による |
12
clock.ts
@@ -20,3 +20,3 @@ import { IterableDict } from './dict'; | ||
assert(this.capacity % BASE === 0); | ||
this.refs = new Uint32Array(this.capacity >>> DIGIT); | ||
this.refs = new Int32Array(this.capacity >>> DIGIT); | ||
} | ||
@@ -26,3 +26,3 @@ private dict = new Map<K, number>(); | ||
private values: (V | undefined | empty)[] = []; | ||
private refs: Uint32Array; | ||
private refs: Int32Array; | ||
private hand = 0; | ||
@@ -41,2 +41,3 @@ private $length = 0; | ||
if (after === before) return; | ||
assert(after >>> 0 !== before >>> 0); | ||
this.refs[i] = after; | ||
@@ -49,2 +50,3 @@ } | ||
if (after === before) return; | ||
assert(after >>> 0 !== before >>> 0); | ||
this.refs[i] = after; | ||
@@ -76,4 +78,4 @@ } | ||
if (b >>> r === ~0 >>> r) { | ||
hand = hand + BASE - r; | ||
refs[i] = 0; | ||
hand += BASE - r; | ||
refs[i] = b & (1 << r) - 1; | ||
r = 0; | ||
@@ -93,4 +95,4 @@ if (hand < capacity) { | ||
if (l !== r) { | ||
hand += l - r; | ||
refs[i] = b & ~((1 << l) - 1 >>> r << r); | ||
hand += l - r; | ||
} | ||
@@ -97,0 +99,0 @@ assert(hand < capacity); |
{ | ||
"name": "spica", | ||
"version": "0.0.798", | ||
"version": "0.0.799", | ||
"description": "Supervisor, Coroutine, Channel, select, AtomicPromise, Cancellation, Cache, List, Queue, Stack, and some utils.", | ||
@@ -57,6 +57,6 @@ "private": false, | ||
"@types/lru-cache": "7.10.9", | ||
"@types/mocha": "10.0.6", | ||
"@types/mocha": "10.0.7", | ||
"@types/power-assert": "1.5.12", | ||
"@types/yallist": "4.0.4", | ||
"@typescript-eslint/parser": "^7.1.1", | ||
"@typescript-eslint/parser": "^7.14.1", | ||
"babel-loader": "^9.1.3", | ||
@@ -68,4 +68,4 @@ "babel-plugin-unassert": "^3.2.0", | ||
"eslint-plugin-redos": "^4.4.5", | ||
"eslint-webpack-plugin": "^4.0.1", | ||
"glob": "^10.3.10", | ||
"eslint-webpack-plugin": "^4.2.0", | ||
"glob": "^10.4.2", | ||
"karma": "^6.4.3", | ||
@@ -77,11 +77,11 @@ "karma-chrome-launcher": "^3.2.0", | ||
"karma-power-assert": "^1.0.0", | ||
"lru-cache": "^10.2.0", | ||
"mocha": "^10.3.0", | ||
"npm-check-updates": "^16.14.15", | ||
"lru-cache": "^10.2.2", | ||
"mocha": "^10.5.1", | ||
"npm-check-updates": "^16.14.20", | ||
"ts-loader": "^9.5.1", | ||
"typescript": "5.4.2", | ||
"webpack": "^5.90.3", | ||
"typescript": "5.4.5", | ||
"webpack": "^5.92.1", | ||
"webpack-cli": "^5.1.4", | ||
"webpack-merge": "^5.10.0", | ||
"yallist": "^4.0.0", | ||
"yallist": "^5.0.0", | ||
"zipfian-integer": "^1.0.1" | ||
@@ -88,0 +88,0 @@ }, |
@@ -21,2 +21,4 @@ import { max } from './alias'; | ||
private readonly retrial: boolean = true, | ||
// ヒットにより前方が増えるためstep=100では不足する。 | ||
private readonly pure: boolean = step >= 100, | ||
) { | ||
@@ -115,3 +117,8 @@ assert(capacity > 0); | ||
dict.set(key, entry); | ||
if (this.handV !== undefined) { | ||
if (this.pure && this.handG !== undefined) { | ||
// 純粋なTLRUの検証用。 | ||
list.insert(entry, this.handG.next); | ||
} | ||
else if (this.handV !== undefined) { | ||
// 基本的にこのほうがヒット率が高い。 | ||
list.insert(entry, this.handV.next); | ||
@@ -118,0 +125,0 @@ } |
850557
0.16%27701
0.06%