4 ms·
Yes, you can do this, but why didn't the code do this in the first place? Because you also want an API that's not annoying and difficult to use. It's a real d
by bsdetector 4y ago
Yes, you can do this, but why didn't the code do this in the first place? Because you also want an API that's not annoying and difficult to use.
It's a real drawback to this transpiler that it takes thread-safe, purely functional code and turns it into code with side effects that have to be carefully managed. Probably due to Go not having a fixed in place stack guarantee.
- tedunangst 4y agoWell, it's not purely functional code. It calls malloc and free. And if you want a multithreaded malloc, you're going to need per thread state.
- bsdetector 4y agoThere are many parts of the code that are functional in C and have side effects in the transpiled version. Look ultimately what we have is a C version and cgo version that are roughly the same speed and a transpiled version that is 1/6th the speed - and the caller can be in any thread in any of those. Then there's a different API where the caller has to manage storage that's on par with the first two, but that's not the same thing. If you jump through these hoops you can be on par is a different claim from what the blog author made. Now it's possible that the wrapper functions could be made fast by storing the TLS object in a Go thread local storage so the API is the same, but the author didn't do this.