Comments (10)
We already have a cache.
So yeah, we could already do this.
Though ideally SwiftPM itself would do this, but we can implement this for now, PR welcome, sources are easy enough to understand and I don't have the time right now.
from swift-sh.
I've made some improvements that I will push shortly, times are all for a pre-built unchanged script:
time | |
---|---|
swift-sh-1.8.4 | 0.421s |
swift-sh-1.8.5 | 0.175s |
swift-run 5.0 | 0.109s |
direct | 0.021s |
I can do more I believe, since we can check if the script mtime is less than the compiled binary mtime unchanged and then just exec which is how make
works, but seems a little risky, but I guess if it's good enough for make it should be good enough for us.
from swift-sh.
K got it down to 0.040s with the above. Further optimizations will be hard. There isn’t a lot more happening that isn’t Swift itself. In theory I'm sure more could be gained, but we are talking about an unnoticeable amount of time now at least. Obviously we’d prefer to have negligible overhead, so PRs welcome.
from swift-sh.
@mxcl Very cool! Thank you very much, it really boosts usability.
from swift-sh.
Notably this introduces a bug that is only present for the Swift 4.2 -> Swift 5.0 transition. I'm not sure as a result if I should fix it.
Because these are not ABI compatible, thus the binaries will fail to run after Xcode is upgraded.
The only fix is to record the swift-tools-version in a file that is then checked before deciding to just run the binary.
However once Swift 5 is installed this no longer becomes necessary… ever again.
I'll think on it.
from swift-sh.
I guess I'll make a quick update that disables this optimization if swift < 5. Sucks a bit, but people having broken scripts and no idea what to do about it sucks more.
from swift-sh.
Hmm needs to be more than this, I need to detect if a script was built against <5 and now swift is >=5.
from swift-sh.
The full solution is to detect the ABI version requirements from the binary somehow and compare that against the current swift version in the path.
Querying swift for it’s version via swift --version
is 20ms. Not sure we can skip this unless we can cache that via mtime querying again and that's complicated considering /usr/bin/swift
is just a shim.
from swift-sh.
So basically I need:
- Fast active swift version lookup
- Fast ABI version lookup for binaries†
† could just assume the generated manifest tools version is this, it’s not exact, but if the manifest version is different then either there's a bug or someone edited it by hand.
Otherwise I have to push this patch that makes the exec time closer to 50–60ms.
from swift-sh.
Also for reference, I built a simple swift app that execs the same pre-built script I was testing with above and it ran between 32–35ms over multiple runs.
from swift-sh.
Related Issues (20)
- Local imports: Cannot use path with spaces
- Scripts don't run on M1 w/ Xcode 12.3 (x86 Homebrew) HOT 2
- Something odd about the 2.2.0 release brew record HOT 2
- Error: reference to member 'v11_1' cannot be resolved without a contextual type.macOS(.v11_1) HOT 3
- Change version to 11 HOT 1
- Fail to import when the package-name and repo-name are not identical HOT 1
- CI won't build linux with swift 5.1
- Brew complaining about outdated formula syntax HOT 1
- Error during installation: Invalid bottle tag symbol HOT 1
- Support scripts w/ `@main` HOT 1
- Dashes in product name breaks dependency resolving HOT 1
- Does not build for release with the Xcode 13 GM HOT 4
- PathKit dependency needs to be updated to 1.0.1 HOT 1
- Error reference to member `v12_1` cannot be resolved HOT 1
- Expose an option that prints the cached build directory? HOT 2
- CI and test failures update & PR links HOT 2
- Editing using `swift sh edit` eventually fails with "The file doesn't exist" HOT 2
- Configurable templates/context HOT 4
- Package not regenerated if you change the import reference HOT 1
- error: The operation couldn’t be completed. (NSPOSIXErrorDomain.13) HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift-sh.