<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>280144</bug_id>
          
          <creation_ts>2024-09-21 22:43:12 -0700</creation_ts>
          <short_desc>Deleting existing entry from Map/Set followed by re-adding is 30x slower than in v8</short_desc>
          <delta_ts>2024-09-29 22:42:19 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>WebKit Local Build</version>
          <rep_platform>Mac (Apple Silicon)</rep_platform>
          <op_sys>macOS 14</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>280600</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Dylan Conway">dylan.conway567</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2062164</commentid>
    <comment_count>0</comment_count>
    <who name="Dylan Conway">dylan.conway567</who>
    <bug_when>2024-09-21 22:43:12 -0700</bug_when>
    <thetext>Example minified from https://github.com/oven-sh/bun/issues/14063

```
var map = new Set();

for (var i = 0; i &lt; 1000; i++) {
    for (var j = 0; j &lt; 1000; j++) {
        map.delete(j);
        map.add(j);
    }
}
```

Running this on an m1 max takes about 1 second with JSC. With v8 it takes about 100 milliseconds.

Switching the order of `delete` and `add`, or combining the loops into a single loop to 1000000 does not seem to repro this behavior.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2062971</commentid>
    <comment_count>1</comment_count>
    <who name="Dylan Conway">dylan.conway567</who>
    <bug_when>2024-09-25 01:07:48 -0700</bug_when>
    <thetext>I suspect this is a bug causing the table to resize too frequently. Removing `shrinkIfNeeded` in `OrderedHashTableHelper::removeImpl` almost brings performance back to normal</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2064065</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-09-28 22:44:18 -0700</bug_when>
    <thetext>&lt;rdar://problem/136912759&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2064159</commentid>
    <comment_count>3</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2024-09-29 22:42:19 -0700</bug_when>
    <thetext>Thanks. Oops, I accidentally opened a new bugzilla for patch upload. Merging it to that as it already has GitHub link.

*** This bug has been marked as a duplicate of bug 280600 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>