<?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>304810</bug_id>
          
          <creation_ts>2025-12-31 12:01:36 -0800</creation_ts>
          <short_desc>High memory usage in WASM compilation thread</short_desc>
          <delta_ts>2026-04-26 15:46:12 -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>WebAssembly</component>
          <version>Safari 26</version>
          <rep_platform>Mac (Apple Silicon)</rep_platform>
          <op_sys>iOS 26</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <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>
          <dependson>307107</dependson>
    
    <dependson>307389</dependson>
    
    <dependson>307583</dependson>
    
    <dependson>307686</dependson>
    
    <dependson>307990</dependson>
    
    <dependson>308158</dependson>
    
    <dependson>309992</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="James Dolan">jdolan</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>furkan.arabaci</cc>
    
    <cc>keith_miller</cc>
    
    <cc>ldenoue</cc>
    
    <cc>nham</cc>
    
    <cc>syg</cc>
    
    <cc>valters.and.co</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2168727</commentid>
    <comment_count>0</comment_count>
    <who name="James Dolan">jdolan</who>
    <bug_when>2025-12-31 12:01:36 -0800</bug_when>
    <thetext>Under certain circumstances I am observing that Safari (26.2 + TP 234) on macOS and iOS can enter a stage of perpetual memory leaking attributed to &quot;Page&quot; that continues even after WASM code exits and eventually results in out-of-memory crash + page reset.

Currently those circumstances appears to be compiling via Emscripten with ASYNCIFY enabled (even if we never hit a Asyncify import), and reading or writing 64-bit values to memory aligned to 4B boundaries.

I have not yet been able to trigger the issue in contrived test so there but I have encountered it in a few different libraries (GLSlang and Tint), this repro (https://github.com/jamesdolan/safari_leak) triggers it in GLSlang and also has a small fix (https://github.com/KhronosGroup/glslang/pull/4137) to avoid the alignment issues that appears to completely avoid the leak.

This leaked memory also does not appear to show up in memory snapshots at all, or really anywhere besides &quot;Page&quot;. And have not been able to find anything in the same order of magnitude when dumping out objects in the js console. So this feels like internal allocations.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2168961</commentid>
    <comment_count>1</comment_count>
    <who name="James Dolan">jdolan</who>
    <bug_when>2026-01-02 16:20:53 -0800</bug_when>
    <thetext>Small update, ASYNCIFY_REMOVE on the functions that do unaligned access also prevents the leak. Guessing the stack save/restore system is bypassing something.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2170052</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2026-01-07 12:02:12 -0800</bug_when>
    <thetext>&lt;rdar://problem/167709015&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2170061</commentid>
    <comment_count>3</comment_count>
    <who name="Keith Miller">keith_miller</who>
    <bug_when>2026-01-07 13:03:56 -0800</bug_when>
    <thetext>Not sure what&apos;s going on here but unaligned load/stores in JSC won&apos;t do anything special (especially on Apple Silicon which natively supports them).

If it&apos;s related to asyncify my guess is that some promise somewhere isn&apos;t running or removing itself from some collection after running although it does seem like that should show up in a heap snapshot...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2183536</commentid>
    <comment_count>4</comment_count>
    <who name="Laurent Denoue">ldenoue</who>
    <bug_when>2026-02-20 14:25:55 -0800</bug_when>
    <thetext>This may cause what we see here https://github.com/microsoft/onnxruntime/issues/26827

This unfortunate bug causes many AI models loaded through ONNX runtime to fail on iOS 26, when it was perfect on iOS 18.

Laurent</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2183541</commentid>
    <comment_count>5</comment_count>
    <who name="Shu-yu Guo">syg</who>
    <bug_when>2026-02-20 14:32:48 -0800</bug_when>
    <thetext>The unaligned loads are likely to have been a red herring. We&apos;ve been addressing this issue and the ONNX issue by improving the greedy register and stack allocators in e.g. 306945@main.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2189769</commentid>
    <comment_count>6</comment_count>
    <who name="Ben Nham">nham</who>
    <bug_when>2026-03-12 15:59:05 -0700</bug_when>
    <thetext>*** Bug 309251 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2204572</commentid>
    <comment_count>7</comment_count>
    <who name="Walter B.">valters.and.co</who>
    <bug_when>2026-04-26 01:59:25 -0700</bug_when>
    <thetext>still present in iOS 26.4.2 - yes it&apos;s related to asyncify

I solved it by running:
wasm-opt &quot;${filename}.wasm&quot; -Oz --asyncify -o &quot;${filename}.wasm&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2204574</commentid>
    <comment_count>8</comment_count>
    <who name="Walter B.">valters.and.co</who>
    <bug_when>2026-04-26 02:01:37 -0700</bug_when>
    <thetext>just to add - maybe this isn&apos;t webkit bug at all, but something in the way emscripten generates asyncify code</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2204640</commentid>
    <comment_count>9</comment_count>
    <who name="James Dolan">jdolan</who>
    <bug_when>2026-04-26 11:23:30 -0700</bug_when>
    <thetext>Cross referencing emscripten issue https://github.com/emscripten-core/emscripten/issues/26027

Also interesting reapplying transform via binarygen appears to resolve issue. Although the fact that memory continues to run away after execution finishes feels like there must be an underlying WebKit issue as well.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2204684</commentid>
    <comment_count>10</comment_count>
    <who name="Walter B.">valters.and.co</who>
    <bug_when>2026-04-26 15:46:12 -0700</bug_when>
    <thetext>in the end the way i could properly prevent crash is this:
wasm-opt &quot;${filename}.wasm&quot; --optimize-instructions --licm  --local-cse --code-pushing --merge-locals --coalesce-locals --asyncify -o &quot;${filename}.wasm&quot;
or better yet (but slower)
wasm-opt &quot;${filename}.wasm&quot; --asyncify  --optimize-instructions --licm  --local-cse --code-pushing --merge-locals --coalesce-locals -o &quot;${filename}.wasm&quot;

it&apos;s essential that --asyncify is included and .wasm is stripped of symbols enough that wasm-opt won&apos;t complain about previous asyncify strings

I analyzed this issue in depth, yes there is definetly an iOS/WebKit  bug, I can zero out wasm memory, remove all timers, remove everything from DOM, remove all messages, everything and it still crashes after about a minute or two once the offending web assembly code has been executed.
This could be both emscripten and iOS bug</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>