[Webkit-unassigned] [Bug 280938] `mnemonist/lru-cache` .set is 28x slower in jsc/bun compared to v8/node

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sat Oct 5 16:00:20 PDT 2024


https://bugs.webkit.org/show_bug.cgi?id=280938

Dylan Conway <dylan.conway567 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dylan.conway567 at gmail.com

--- Comment #2 from Dylan Conway <dylan.conway567 at gmail.com> ---
Minimized repro:

```
const CAPACITY = 1000;

class LRUCache {
    constructor() {
        this.backward = [];
        this.keys = [];
        this.size = 0;
        this.head = 0;
        this.tail = 0;
        this.items = {};
    }
    set(key) {
        var pointer = this.items[key];
        if (this.size < CAPACITY) {
            pointer = this.size++;
        } else {
            pointer = this.tail;
            this.tail = this.backward[pointer];
            delete this.items[this.keys[pointer]];
        }
        this.items[key] = pointer;
        this.keys[pointer] = key;
        this.backward[this.head] = pointer;
        this.head = pointer;
    }
}

var lru = new LRUCache();

for (let i = 0; i < CAPACITY; i++) {
    for (let j = 0; j < CAPACITY * 2; j++) {
        lru.set("hi" + j);
    }
}
```

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20241005/165a2440/attachment.htm>


More information about the webkit-unassigned mailing list