News for hackers. Stuff that matters.
Re:Go port of SQLite without CGo by eatonphil on Friday April 07, 2023 @08:52PM (#35489192)
It's a really neat project. I did some simple benchmarks of it and it was between 10% slower to twice as slow. Which depending on your use case isn't that bad!

https://datastation.multiprocess.io/blog/2022-05-12-sqlite-i...

Re:Go port of SQLite without CGo by philosopher1234 on Friday April 07, 2023 @09:07PM (#35489311)
What makes it slower?
Re:Go port of SQLite without CGo by cube2222 on Friday April 07, 2023 @09:23PM (#35489415)
Other than what the other responders said, since it uses a C to Go compiler, I'd imagine the Go code that's generated isn't as fast as handwritten Go code could be.
Re:Go port of SQLite without CGo by djbusby on Friday April 07, 2023 @11:13PM (#35490126)
C -> GPT -> Go -> Edit -> commit?
Re:Go port of SQLite without CGo by pkolaczk on Saturday April 08, 2023 @03:03AM (#35491211)
-> fail to compile / crash at startup
Re:Go port of SQLite without CGo by cdogl on Friday April 07, 2023 @09:12PM (#35489343)
It’s hard for Go to beat C in a straight benchmark - Go is garbage collected and allocations often have extra overhead due to the memory layout of interfaces.
Re:Go port of SQLite without CGo by icholy on Friday April 07, 2023 @11:13PM (#35490133)
In addition, a lot of optimizations (like loop unrolling) are left on the table to preserve Go's fast compile times.
Re:Go port of SQLite without CGo by pjmlp on Saturday April 08, 2023 @01:08AM (#35490726)
Gccgo is the answer here.
Re:Go port of SQLite without CGo by Patrickmi on Saturday April 08, 2023 @08:06AM (#35492475)
Gccgo at its core may be fast but when it comes to how the go frontend interpret it to gcc ir that pales in comparison than just straight up optimizating the Go compiler

There’ll more opportunities for more optimizations since they move to SSA ir since 1.5 and in turn compile time will definitely go down

Re:Go port of SQLite without CGo by 59nadir on Saturday April 08, 2023 @03:23AM (#35491306)
I was surprised with the announcement that Go's standard compiler had register allocation for function arguments[0] added to it. This seemed like table stakes for a very long time but it really illustrated just how Go's compiler is much, much simpler than most in many areas.

On one hand it makes you wonder how much could be squeezed out of Go and how many basic things they're still leaving out of the compiler. On the other it tells part of the story of why Go compiles fast with the backdrop that despite this lack of work by the compiler people use Go productively all day and deliver services they are happy with from a performance perspective.

[0] - https://go.dev/doc/go1.17#compiler (2021-08)

Re:Go port of SQLite without CGo by zimpenfish on Saturday April 08, 2023 @04:05AM (#35491505)
I wonder if they'll ever switch to a "normal = fast compile, low optimisation; release = slow compile, high optimisation" model like Rust. Although I suppose other languages already have the "high optimisation" parts covered (rust, julia, python+numpy, etc.) which might make it a fool's errand.
Re:Go port of SQLite without CGo by Mawr on Saturday April 08, 2023 @06:35PM (#35498320)
It goes to show the impact of optimizing from top-down instead of bottom-up can have. Go was designed with performance in mind ("mechanical sympathy") as opposed to most other GC languages for which performance was an afterthought.

Structs instead of objects, value types, exposed pointers, straightforward allocation semantics.

Do these machine-optimized constructs impede productivity? Yes, but by maybe 20%, whereas the performance gain is 80%.

Re:Go port of SQLite without CGo by pjmlp on Saturday April 08, 2023 @01:07AM (#35490724)
It is a matter of skill, Go can do manual memory management and stack allocation just as well.
Re:Go port of SQLite without CGo by kaba0 on Saturday April 08, 2023 @02:14AM (#35490976)
Also, Go barely optimizes code, that’s how it compiles as fast.
Re:Go port of SQLite without CGo by pkolaczk on Saturday April 08, 2023 @03:00AM (#35491188)
Not only Go compiler is not as good at optimisation as C/C++/Rust/Zig/D compilers, but also Go FFI to C has significant overhead, which means there is often not much point in using low-level Linux APIs for performance advantage. Same problem like with Java. And in a database system you quite likely want a fine degree of control with non-standard stuff.
Re:Go port of SQLite without CGo by yencabulator on Sunday April 09, 2023 @01:34PM (#35504748)
However, it is absolutely plausible for Go-calling-Go to beat Go-calling-C-via-CGo, since CGo has plenty of overhead.
Re:Go port of SQLite without CGo by platzhirsch on Friday April 07, 2023 @09:09PM (#35489323)
My guess is that over the years many optimizations have gone into SQLite that would take a lot of effort to catch up to.
Re:Go port of SQLite without CGo by carbocation on Friday April 07, 2023 @10:27PM (#35489874)
I raised this question on twitter awhile back and the response that I got was that (for read-only tasks) the connection string might ameliorate this. I haven't been able to test it, though:

https://twitter.com/frioux/status/1483235674228596739

Re:Go port of SQLite without CGo by collinvandyck76 on Friday April 07, 2023 @11:03PM (#35490066)
at segment we benchmarked https://github.com/segmentio/ctlstore against this driver. We saw about a 50% hit to read performance, so we didn't move forward with it, but the improvements in service build times were really appealing.
Re:Go port of SQLite without CGo by djbusby on Friday April 07, 2023 @11:11PM (#35490118)
Really tho, how much is build time vs runtime? Maybe is just work small projects but I rarely care about build time. Am I missing something?
Re:Go port of SQLite without CGo by badtuple on Friday April 07, 2023 @11:41PM (#35490310)
Honestly, on a non-toy project, build times with cgo are _brutal_. I agree with you usually, but when a build time on a beefy computer switches from under a second to >1min you notice it

Linters and IDEs get slow when they check for errors, tests run slow, feedback drags, and all your workflows that took advantage of Go's fast compile times are now long enough that your flow and mental context disappear.

Re:Go port of SQLite without CGo by bombolo on Saturday April 08, 2023 @02:43AM (#35491119)
Why would you have to recompile sqlite every time?

I guess you just need to compile the .a once and then just reuse it?

If you're rebuilding it every single time, your build is set up wrong.

Re:Go port of SQLite without CGo by _ph_ on Saturday April 08, 2023 @09:08AM (#35492772)
In my experience, encapsulating the access to sqlite in a go package helps a lot with avoiding recompilation of the c source, which indeed is brutally slow. It acutally seems to be way slower than compiling with gcc from the command line. Anyone knows why this is the case?
Re:Go port of SQLite without CGo by collinvandyck76 on Friday April 07, 2023 @11:24PM (#35490212)
If you have a lot of people and a lot of different builds it can become increasingly significant. It wasn't in our case, but it felt like it could have become so. And a lot of services wouldn't really notice too much if the occasional read from disk was slower, given that the nature of the data was control data.
Re:Go port of SQLite without CGo by emodendroket on Saturday April 08, 2023 @12:01AM (#35490410)
I’d go so far as to say it’s completely acceptable for 90+% of use cases.