Skip to content

Conversation

@aheejin
Copy link
Member

@aheejin aheejin commented Jan 28, 2026

moveSecondaryFunctions, despite the name, actually copies functions to secondary modules and removes them from the primary module. This prevents this overhead by actually moving the functions to secondary modules. This reduces the running time on acx_gallery (provided by @biggs0125) by 31%.


  • Before this PR:
    Time: 16.4s
    Task breakdown:
Task                                          Total Time (ms)      Percentage
---------------------------------------------------------------------------
moveSecondaryFunctions                              5341.1700          43.94%
writeModule_secondary                               2960.8319          24.36%
shareImportableItems                                1568.6400          12.91%
writeModule_primary                                  765.7240           6.30%
exportImportCalledPrimaryFunctions                   762.9670           6.28%
indirectReferencesToSecondaryFunctions               362.3300           2.98%
classifyFunctions                                    204.4540           1.68%
indirectCallsToSecondaryFunctions                    139.2110           1.15%
setupTablePatching                                    45.2461           0.37%
thunkExportedSecondaryFunctions                        3.0373           0.02%
initExportedPrimaryFuncs                               0.9982           0.01%
---------------------------------------------------------------------------
Overall Total                                      12154.6095         100.00%
  • After this PR:
    Time: 11.3s
    Task breakdown:
Task                                          Total Time (ms)      Percentage
---------------------------------------------------------------------------
writeModule_secondary                               2908.4728          43.52%
shareImportableItems                                1562.7800          23.39%
exportImportCalledPrimaryFunctions                   786.6140          11.77%
writeModule_primary                                  751.3420          11.24%
indirectReferencesToSecondaryFunctions               250.7260           3.75%
indirectCallsToSecondaryFunctions                    149.7940           2.24%
classifyFunctions                                    126.4520           1.89%
moveSecondaryFunctions                               106.0680           1.59%
setupTablePatching                                    38.9292           0.58%
initExportedPrimaryFuncs                               0.8816           0.01%
thunkExportedSecondaryFunctions                        0.4937           0.01%
---------------------------------------------------------------------------
Overall Total                                       6682.5533         100.00%

We can see the time spent in moveSecondaryFunctions, which used to take nearly half of the running time (after #8221), is now negligible.

`moveSecondaryFunctions`, despite the name, actually copies functions to
secondary modules and removes them from the primary module. This
prevents this overhead by actually moving the functions to secondary
modules. This reduces the running time on acx_gallery (provided by
@biggs0125) by 31%.

---

- Before this PR:
  Time: 16.4s
  Task breakdown:
```
Task                                          Total Time (ms)      Percentage
---------------------------------------------------------------------------
moveSecondaryFunctions                              5341.1700          43.94%
writeModule_secondary                               2960.8319          24.36%
shareImportableItems                                1568.6400          12.91%
writeModule_primary                                  765.7240           6.30%
exportImportCalledPrimaryFunctions                   762.9670           6.28%
indirectReferencesToSecondaryFunctions               362.3300           2.98%
classifyFunctions                                    204.4540           1.68%
indirectCallsToSecondaryFunctions                    139.2110           1.15%
setupTablePatching                                    45.2461           0.37%
thunkExportedSecondaryFunctions                        3.0373           0.02%
initExportedPrimaryFuncs                               0.9982           0.01%
---------------------------------------------------------------------------
Overall Total                                      12154.6095         100.00%
```

- After this PR:
  Time: 11.3s
```
Task                                          Total Time (ms)      Percentage
---------------------------------------------------------------------------
writeModule_secondary                               2908.4728          43.52%
shareImportableItems                                1562.7800          23.39%
exportImportCalledPrimaryFunctions                   786.6140          11.77%
writeModule_primary                                  751.3420          11.24%
indirectReferencesToSecondaryFunctions               250.7260           3.75%
indirectCallsToSecondaryFunctions                    149.7940           2.24%
classifyFunctions                                    126.4520           1.89%
moveSecondaryFunctions                               106.0680           1.59%
setupTablePatching                                    38.9292           0.58%
initExportedPrimaryFuncs                               0.8816           0.01%
thunkExportedSecondaryFunctions                        0.4937           0.01%
---------------------------------------------------------------------------
Overall Total                                       6682.5533         100.00%
```

We can see the time spent in `moveSecondaryFunctions`, which used to
take nearly half of the running time (after WebAssembly#8221), is now negligible.
Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this safe? This will end up with a Module containing expressions allocated on an arena owned by another Module. We'd have to be very careful to make sure no module outlives any of the others.

@aheejin
Copy link
Member Author

aheejin commented Jan 28, 2026

You're right. I didn't think about that... But apparently in this case it's kinda ok because the primary module is not destroyed until the end of multiSplitModule / splitModule.

But apparently 15s->10s speedup is not a game-changer (because the merge-optimization-split workflow is now anyway dominated by the optimization), so introducing this risky dependency might not be worth it.

@aheejin aheejin closed this Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants