News for hackers. Stuff that matters.
Re:Interoperability: Swift’s Super Power by pjmlp on Friday September 22, 2023 @08:40AM (#37611226)
Typescript is limited by V8 capabilities, and the constraints of a dynamic language JIT. To achieve best perfomance one needs to write C++ code as native modules.

Interoperable means a lot even inside Apple ecosystem, bringing all those C, Objective-C and now C++ code with ease into Swift projects.

Using Metal from Swift, althought implemented in Objective-C and C++, is already a productivity boost compared to anything that Microsoft has ever produced for .NET in regards to DirectX, not even XNA.

Re:Interoperability: Swift’s Super Power by auggierose on Friday September 22, 2023 @10:18AM (#37612391)
If you are on the Apple platform only, Swift is great, and I enjoyed using Metal myself. But eventually I accepted how much it limited what I can do as a developer. So, I prefer TypeScript now. I am not touching C++ or stuff like that, if I need performance, I compile to web assembly, hopefully soon from my own language :-)
Re:Interoperability: Swift’s Super Power by pjmlp on Friday September 22, 2023 @11:08AM (#37613051)
Web Assembly and performance on the same sentene is an oxymoron.
Re:Interoperability: Swift’s Super Power by auggierose on Friday September 22, 2023 @12:26PM (#37614071)
WebGPU + WebAssembly + TypeScript is going to be a pretty potent combo. I doubt Swift + Metal is more performant. Actually, when I translated some Swift code to JavaScript, it ran faster.
Re:Interoperability: Swift’s Super Power by pjmlp on Friday September 22, 2023 @12:44PM (#37614286)
WebGPU exposes 2015 hardware.

If you failed to make Swift + Metal perform better than JavaScript, there is something really horrible with your code.

Re:Interoperability: Swift’s Super Power by auggierose on Friday September 22, 2023 @04:02PM (#37617010)
I'd say there are plenty of use cases where access to 2015 hardware capabilities is more than enough, given that you will profit from any automatic speed improvements beyond 2015 hardware as well. Which features beyond 2015 are you referring to?

The code I ported wasn't Swift+Metal, it was just Swift. It certainly wasn't optimized in any way, but the Javascript one wasn't either. Javascript data structures are just faster, because they are fully imperative, the Swift ones are more expensive, despite some copy-on-write tricks. And remember, carefully written Javascript is just as fast as C.

Re:Interoperability: Swift’s Super Power by pjmlp on Friday September 22, 2023 @04:14PM (#37617174)
Mesh shaders, ray tracing, unified memory, direct IO,...

V8 JIT is hardly as fast as C, almost there yeah, there is still a speed bump.

Re:Interoperability: Swift’s Super Power by auggierose on Friday September 22, 2023 @06:02PM (#37618366)
Yes, if you need these things, you will have to go native (although you will probably automatically benefit from unified memory).

For many many things, you won't, and then the ability to target Apple/Windows/Linux with exactly the same code, pain-free GPU access etc, that's just great. The other day I checked if I can access from the browser the 3D coordinates of my space mouse, and it just works, based on a standard Web API (GamePad API). While from Swift, it would be a hassle to setup and maintain.

Re:Interoperability: Swift’s Super Power by mst on Friday September 22, 2023 @11:03AM (#37612991)
I'd note that I've seen cases where the V8 JIT was sufficiently good that thunking to C++ and back meant that the performance difference was minimal.

But that was for 'js library backed by C++' shaped cases whereas for performance critical app-specific code you probably want 'C++ library that presents a JS interface at the top level.'