Closed
Bug 1927405
Opened 4 months ago
Closed 3 months ago
Map/Set clear function is slow
Categories
(Core :: JavaScript Engine, task, P1)
Core
JavaScript Engine
Tracking
()
RESOLVED
FIXED
134 Branch
Tracking | Status | |
---|---|---|
firefox134 | --- | fixed |
People
(Reporter: jandem, Assigned: jandem)
References
Details
(Whiteboard: [sp3])
Attachments
(1 file)
If the Map
or Set
is not empty, clear()
always does a malloc
+ free
. We should change this to instead destroy all elements and then only shrink the table if needed, similar to how remove
works.
This also avoids calling init()
after the table has been initialized and this simplifies bug 1851662.
Changing this improves the micro-benchmark below from ~105 ms to ~35 ms.
function f() {
var s = new Set;
var t = new Date;
for (var i = 0; i < 1_000_000; i++) {
s.add(1);
s.clear();
}
print(new Date - t);
return s;
}
f();
Assignee | ||
Comment 1•4 months ago
|
||
Change clear
to destroy all elements and then shrink the table only if needed,
similar to how remove
is implemented.
This eliminates a free
and malloc
if there are only a few elements but it's also
simpler because it avoids calling init
more than once which is a footgun.
Updated•4 months ago
|
Severity: -- → N/A
Priority: -- → P1
Pushed by jdemooij@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/a07d438ea22a
Simplify and optimize OrderedHashTable::clear. r=jonco
Comment 3•3 months ago
|
||
bugherder |
Status: ASSIGNED → RESOLVED
Closed: 3 months ago
status-firefox134:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → 134 Branch
Updated•3 months ago
|
Whiteboard: [sp3]
Updated•3 months ago
|
See Also: → https://mozilla-hub.atlassian.net/browse/SP3-840
You need to log in
before you can comment on or make changes to this bug.
Description
•