Avoid generating trampolines with --no-placeholders

Aperta
#8,238 12 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Tranquilla
Stack tecnologico
cpp, wasm
Ambito
compilers

Direzione di ricerca

Inizia da src/ir/module-splitting.cpp nei due punti collegati e verifica come wasm-split gestisce --no-placeholders. Esamina il numero di trampoline e se Dart o altre informazioni sul caricamento dei moduli possano stabilire l’ordine delle dipendenze. Il lavoro è completato quando esiste un contratto di input o di loader definito che consenta in sicurezza le riduzioni di trampoline previste.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

The wasm-split options --no-placeholders is used when the module loader can guarantee that secondary modules will be loaded before their functions are ever called. It currently has the effect of avoiding the creation of imported placeholder functions that are meant to lazily load secondary modules on demand, since these placeholders will never be run.

But we could also use the guarantee that the loader will have loaded modules before they are needed to avoid generating trampoline functions in many cases. We currently generate trampoline functions for two situations: 1) for secondary functions that are exported from the primary module (link), and 2) for secondary functions that are referenced from a different module (link).

For case 1), if modules are always loaded before they are needed, then exported secondary functions will never be called before their modules are loaded. We could therefore require the loader to append public secondary exports to the list of primary exports itself when it loads secondary modules rather than using a trampoline to provide the export from the primary module.

For case 2), we still need trampolines for secondary functions referenced from the primary module, since we cannot import those functions and we must have something to reference. But we might be able to avoid creating trampolines for secondary functions referenced from other secondary modules that we know will be loaded later. We would instead depend on the loader to append the exports from each loaded secondary module to the imports provided to the next, so later secondary modules could reference functions imported from earlier secondary modules directly.

The trouble here is knowing which secondary modules are "earlier" or "later" than others so we know which trampolines we can elide. The most explicit way to know this would be to have the user pass in a module dependence graph, perhaps as part of the manifest file. Alternatively we could depend on other information provided by the user. For example, we could provide a flag to let the user assert that modules only reference functions from earlier modules, which would then allow us to unconditionally skip inserting trampolines.

@biggs0125, is it the case that Dart modules will only reference functions provided by earlier Dart modules? If not, would it be feasible to pass a module dependence graph to wasm-split to help it improve its codegen?

@aheejin, does this optimization sound useful to you? It might be worth doing some preliminary investigation to see how many trampolines we are generating and how many are exported from the primary module and imported into secondary modules.

Lingua principale
WebAssembly
Stelle
8.6k
Fork
885
Merge medio
2g 1h
PR unite (30g)
70

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di WebAssembly/binaryen

Tutte le issue di WebAssembly/binaryen

Issue simili

Altre issue su Compilers

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.