Git Product home page Git Product logo

Comments (10)

mxcl avatar mxcl commented on May 29, 2024

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.

mxcl avatar mxcl commented on May 29, 2024

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.

mxcl avatar mxcl commented on May 29, 2024

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.

zmeyc avatar zmeyc commented on May 29, 2024

@mxcl Very cool! Thank you very much, it really boosts usability.

from swift-sh.

mxcl avatar mxcl commented on May 29, 2024

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.

mxcl avatar mxcl commented on May 29, 2024

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.

mxcl avatar mxcl commented on May 29, 2024

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.

mxcl avatar mxcl commented on May 29, 2024

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.

mxcl avatar mxcl commented on May 29, 2024

So basically I need:

  1. Fast active swift version lookup
  2. 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.

mxcl avatar mxcl commented on May 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.