Skip to content

builder: link package modules with a single Linker - #5979

Draft
joeshaw wants to merge 2 commits into
tinygo-org:devfrom
joeshaw:builder-single-linker
Draft

joeshaw wants to merge 2 commits into
tinygo-org:devfrom
joeshaw:builder-single-linker

Conversation

@joeshaw

@joeshaw joeshaw commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

TinyGo side follow up to tinygo-org/go-llvm#86

llvm.LinkModules creates a new llvm::Linker for every package, and each one collects the struct types of the whole destination module first, so linking grew quadratically with the number of packages. For a program with ~250 packages this took 29s; with one Linker for all of them it takes 8s. The generated code is unchanged.

llvm.LinkModules creates a new llvm::Linker for every package, and each one
collects the struct types of the whole destination module first, so linking
grew quadratically with the number of packages.  For a program with ~250
packages this took 29s; with one Linker for all of them it takes 8s.  The
generated code is unchanged.
@joeshaw

joeshaw commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Submitted as a draft until that go-llvm PR lands, as CI can't pass until that happens and this PR is updated to point go.mod at the new commit hash.

@dgryski

dgryski commented Oct 21, 2026

Copy link
Copy Markdown
Member

🤖

Each early return has its own linker.Dispose(). A single defer linker.Dispose() right after NewLinker is less error-prone. A defer inside the callback runs at the end of the job function, which is only slightly later than the current explicit call. If the later code in that function needs the Linker disposed before it runs, keep the explicit call.

The error from linker.LinkModule(globalsMod) is ignored. The old llvm.LinkModules(mod, globalsMod) call ignored it too, so this isn't a regression. Checking it would be a cheap improvement

@joeshaw

joeshaw commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, both done in 08f0674.

@dgryski dgryski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM (once go-llvm fix is merged and this is rebased)

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