<div>For the interpreter, it's acceptable since it's got the debugger in there; but for the scripting mode it's a real obstruction.</div><div><br><div class="gmail_quote"><div>Keith Smiley <k@keith.so> schrieb am Mo. 20. Feb. 2017 um 11:25:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">A related issue that's worth mentioning is the overhead of running a<br class="gmail_msg">
Swift script in general. Here's the simplest of examples of Swift vs<br class="gmail_msg">
Python:<br class="gmail_msg">
<br class="gmail_msg">
```<br class="gmail_msg">
$ cat helloworld<br class="gmail_msg">
print("Hello World")<br class="gmail_msg">
<br class="gmail_msg">
Cold:<br class="gmail_msg">
<br class="gmail_msg">
$ time swift helloworld<br class="gmail_msg">
Hello World<br class="gmail_msg">
swift helloworld 0.06s user 0.44s system 67% cpu 0.746 total<br class="gmail_msg">
$ time python helloworld<br class="gmail_msg">
Hello World<br class="gmail_msg">
python helloworld 0.01s user 0.01s system 22% cpu 0.095 total<br class="gmail_msg">
<br class="gmail_msg">
Warm:<br class="gmail_msg">
<br class="gmail_msg">
$ time swift helloworld<br class="gmail_msg">
Hello World<br class="gmail_msg">
swift helloworld 0.04s user 0.01s system 22% cpu 0.212 total<br class="gmail_msg">
$ time python helloworld<br class="gmail_msg">
Hello World<br class="gmail_msg">
python helloworld 0.02s user 0.01s system 84% cpu 0.035 total<br class="gmail_msg">
```<br class="gmail_msg">
<br class="gmail_msg">
While we're thinking about this for scripting, I think it's tangentially<br class="gmail_msg">
related that the repl has a similar difference in overhead:<br class="gmail_msg">
<br class="gmail_msg">
```<br class="gmail_msg">
$ time swift <<< ":quit"<br class="gmail_msg">
Welcome to Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1). Type :help for assistance.<br class="gmail_msg">
swift <<< ":quit" 1.88s user 0.23s system 86% cpu 2.459 total<br class="gmail_msg">
<br class="gmail_msg">
$ time python <<< "quit()"<br class="gmail_msg">
python <<< "quit()" 0.01s user 0.01s system 81% cpu 0.030 total<br class="gmail_msg">
```<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
--<br class="gmail_msg">
Keith Smiley<br class="gmail_msg">
<br class="gmail_msg">
On 02/19, Jason Dusek via swift-build-dev wrote:<br class="gmail_msg">
> One issue with compiling the dependencies is that script startup would be<br class="gmail_msg">
> slow. Maybe there should be a per-user or system level cache? System level<br class="gmail_msg">
> is better from a disk usage perspective but some thought must be given to<br class="gmail_msg">
> security.<br class="gmail_msg">
><br class="gmail_msg">
> With Ruby and Python, it is not expected that a script's dependencies are<br class="gmail_msg">
> installed when it is run but rather they have already been installed via<br class="gmail_msg">
> the package manager, although it does seem useful for single files to<br class="gmail_msg">
> contain all the relevant information.<br class="gmail_msg">
><br class="gmail_msg">
> Here is another idea: a Swift script can be run from a project directory<br class="gmail_msg">
> with Sources/, Packages/, &c. In that environment, build products are<br class="gmail_msg">
> already cached. If the script is symlinked into /usr/local/bin/ it will be<br class="gmail_msg">
> on the path but xcrun will still be able to find the project. It is kind of<br class="gmail_msg">
> like a source-level .app bundle.<br class="gmail_msg">
><br class="gmail_msg">
> Maxim Veksler via swift-build-dev <<a href="mailto:swift-build-dev@swift.org" class="gmail_msg" target="_blank">swift-build-dev@swift.org</a>> schrieb am<br class="gmail_msg">
> Sa. 18. Feb. 2017 um 11:28:<br class="gmail_msg">
><br class="gmail_msg">
> > Hi,<br class="gmail_msg">
> ><br class="gmail_msg">
> > Ayaka Nonaka gave a talk[1] about basic scripting[2] support in Swift.<br class="gmail_msg">
> ><br class="gmail_msg">
> > The gist of the idea is to use #!/usr/bin/env xcrun swift<br class="gmail_msg">
> ><br class="gmail_msg">
> > Therefor it seems the basic building blocks for allowing a swift file to<br class="gmail_msg">
> > "execute itself" are always laid out and proved to be applicable.<br class="gmail_msg">
> ><br class="gmail_msg">
> > What's missing IMHO is a better support for dependencies, the suggested<br class="gmail_msg">
> > solutions in the talk are using the -F for including frameworks that were<br class="gmail_msg">
> > built using Carthage or CocoaPods. That's not idle because a script I think<br class="gmail_msg">
> > should be self contained, meaning that you can "just run it" and it works.<br class="gmail_msg">
> ><br class="gmail_msg">
> > So, I'm wondering what if it was possible to include the dependencies<br class="gmail_msg">
> > inside the swift file itself? Probably using the same format as the<br class="gmail_msg">
> > Package.swift syntax. The the swift binary would "detect" that it's a self<br class="gmail_msg">
> > contained file, it could make this distinction because import<br class="gmail_msg">
> > PackageDescription is defined by the user.<br class="gmail_msg">
> ><br class="gmail_msg">
> > Then it would follow a 3 step process:<br class="gmail_msg">
> > 1. It should download and build the dependencies<br class="gmail_msg">
> > 2. then compile the code inside the file<br class="gmail_msg">
> > 3. and then run it.<br class="gmail_msg">
> ><br class="gmail_msg">
> > Having everything happening behind the scenes, so the "script user" simply<br class="gmail_msg">
> > calls ./MyScript.swift or swift MyScript.swift and it "just works".<br class="gmail_msg">
> ><br class="gmail_msg">
> > Wondering what the community thinks.<br class="gmail_msg">
> ><br class="gmail_msg">
> > [1] <a href="https://realm.io/news/swift-scripting/" rel="noreferrer" class="gmail_msg" target="_blank">https://realm.io/news/swift-scripting/</a><br class="gmail_msg">
> > [2] <a href="https://github.com/ayanonagon/talks/tree/master/2015-swiftsummit/2" rel="noreferrer" class="gmail_msg" target="_blank">https://github.com/ayanonagon/talks/tree/master/2015-swiftsummit/2</a><br class="gmail_msg">
> > _______________________________________________<br class="gmail_msg">
> > swift-build-dev mailing list<br class="gmail_msg">
> > <a href="mailto:swift-build-dev@swift.org" class="gmail_msg" target="_blank">swift-build-dev@swift.org</a><br class="gmail_msg">
> > <a href="https://lists.swift.org/mailman/listinfo/swift-build-dev" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-build-dev</a><br class="gmail_msg">
> ><br class="gmail_msg">
<br class="gmail_msg">
> _______________________________________________<br class="gmail_msg">
> swift-build-dev mailing list<br class="gmail_msg">
> <a href="mailto:swift-build-dev@swift.org" class="gmail_msg" target="_blank">swift-build-dev@swift.org</a><br class="gmail_msg">
> <a href="https://lists.swift.org/mailman/listinfo/swift-build-dev" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-build-dev</a><br class="gmail_msg">
<br class="gmail_msg">
</blockquote></div></div>