kabiroberai / node-swift

Create Node modules in Swift
MIT License
472 stars 15 forks source link

Slow builds #22

Closed shirakaba closed 3 months ago

shirakaba commented 3 months ago

Loving node-swift, just wish libraries compiled faster!

I find that a warm build with node-swift rebuild [--debug] is very slow (~18 seconds on a M3 Max for a small change made to a basic six-file project) compared node-gyp on an equivalent warm build for a project written in Objective-C++ (<3 seconds, if I recall correctly).

In the console logs, I see node-swift rebuild spending a fair amount of time recompiling a bunch of unchanged files that have been compiled previously, like swift-syntax. Is there any way builds could be made faster, perhaps by caching this work (if it isn't already) or precompiling some of the dependencies? Thanks!

kabiroberai commented 3 months ago

It's a bit difficult to do this as it currently stands, because SwiftPM doesn't have a good way to cache SwiftSyntax out of the box — see this Swift Forums thread: Compilation extremely slow since macros adoption. I'm actually working on a long-term solution in the form of WebAssembly Macros but it might take a while before that's generally available.

However, note that this only applies to clean builds; incremental builds do already benefit from caching. node-swift rebuild performs a clean build, but you can make it incremental using node-swift build instead. Let me know if that helps!

shirakaba commented 3 months ago

Oh man, that really does the trick. Think I tunnel-visioned in on node-swift rebuild as I just copied the example in the repo as-is, so effectively I was always doing a cold build because rebuild performs a clean, as you say. It turns out that a warm run of node-swift build --debug goes as fast as 0.33s. Thanks! 🥹