Live data from Hacker News

I benchmarked six Go SQLite drivers

github.com

51–60 of 64 posts

Re: I benchmarked six Go SQLite drivers

#51
I'm the author or the WASM (+wazero) based github.com/ncruces/go-sqlite3. Happy to field questions.

W.r.t. benchmark results.

wazero's current compiler is somewhat naive, which may explain a large performance delta in CPU bound tests. A new compiler is in the works [1].

OTOH it seems interesting that in the (IO bound?) large test I'm doing better than modernc. I wonder why.

I'll dig deeper into the results.

[1]: https://github.com/tetratelabs/wazero/pull/1869

Re: I benchmarked six Go SQLite drivers

#52
post #12

In my personal opinion and usage, the performance doesn't matter. Only one driver is written in pure go, and can be easily statically compiled and/or cross-compiled. > modernc, modernc.org/sqlite, a pure Go solution. This is a newer library, based on the SQLite C code re-written in Go. Unless I'm mistaken, this is not a re-write in Go. This is a transpilation of the the SQLite C library into go, using https://gitlab.…

> Only one driver is written in pure go, and can be easily statically compiled and/or cross-compiled. Which one do you mean? The WASM one? It includes WASM, it needs to be compiled too. Ah github.com/cvilsmeier/sqinn-go. Which... is made by the same person that made this benchmark...? edit: and that requires some random binary to be pre-installed...? Which is in C anyway? https://github.com/cvilsmeier/sqinn-go https:…

For the WASM one (disclaimer: I built it) it's at least reasonably simple to reproduce the build [1], and the resulting blob is fully cross platform.

Also, although I do (lightly) patch SQLite which might invalidate results in your view, the SQLite team is producing/testing/releasing WASM builds of SQLite built with much the same toolchain, which, hopefully, smokes out compiler bugs.

[1]: https://github.com/ncruces/go-sqlite3/blob/main/.github/work...

Re: I benchmarked six Go SQLite drivers

#53

Earlier quoted context omitted.

That stood out to me as well. Any insights why sqinn and zombie underperform in this case, and is the problem inherent to their design?

For sqinn it's because of its design: Shuffling that much data over process boundaries takes time. For zombie, more pprof would be needed to explain the behaviour.

I would suspect some unnecessary copying. Nothing else explains a “lower level” binding (zombie) performing worse than modernc.

My (WASM) binding also has a lower level API. But I worked hard to make database/sql work first class, so I wouldn't expect much improvement.

Re: I benchmarked six Go SQLite drivers

#54

There was a comment from https://news.ycombinator.com/user?id=HackerThemAll with neutral rating that was likely taken down by a mod action despite not violating the rules. I am reposting it below shortly with minor stylistic changes for politeness. “Go's SQLite drivers exhibit surprisingly poor performance. In C# I was able to conduct 2 millions of point queries per second on my laptop. And it's not the fastest langu…

FFI was high priority for C# in the early days, when most meaningful .NET software was running on Windows and doing interop with win32. The runtime was designed to ensure that scenario would be low-overhead, and that legacy lives on in modern .NET.

Re: I benchmarked six Go SQLite drivers

#55
post #12

In my personal opinion and usage, the performance doesn't matter. Only one driver is written in pure go, and can be easily statically compiled and/or cross-compiled. > modernc, modernc.org/sqlite, a pure Go solution. This is a newer library, based on the SQLite C code re-written in Go. Unless I'm mistaken, this is not a re-write in Go. This is a transpilation of the the SQLite C library into go, using https://gitlab.…

zombiezen.com/go/sqlite is built on top of modernc.org/sqlite, so also has the same properties.

How come Zombiezen came out faster ? I’d expect the opposite

Re: I benchmarked six Go SQLite drivers

#56

Earlier quoted context omitted.

zombiezen.com/go/sqlite is built on top of modernc.org/sqlite, so also has the same properties.

How come Zombiezen came out faster ? I’d expect the opposite

> How come Zombiezen came out faster ? I’d expect the opposite

(OP here) Honestly, me too. Maybe it has to do with leaving out that database/sql driver layer. I guess it would need another round of pprof to find out the real reason.

Re: I benchmarked six Go SQLite drivers

#57
post #40

Earlier quoted context omitted.

> Only one driver is written in pure go, and can be easily statically compiled and/or cross-compiled. Which one do you mean? The WASM one? It includes WASM, it needs to be compiled too. Ah github.com/cvilsmeier/sqinn-go. Which... is made by the same person that made this benchmark...? edit: and that requires some random binary to be pre-installed...? Which is in C anyway? https://github.com/cvilsmeier/sqinn-go https:…

The modernc one is the one I was refering to. https://gitlab.com/cznic/sqlite

But that's not pure go, that's C transpiled to go, but even the transpilation is using OS specific and CPU-specific unsafe code.

Re: I benchmarked six Go SQLite drivers

#58
post #54

There was a comment from https://news.ycombinator.com/user?id=HackerThemAll with neutral rating that was likely taken down by a mod action despite not violating the rules. I am reposting it below shortly with minor stylistic changes for politeness. “Go's SQLite drivers exhibit surprisingly poor performance. In C# I was able to conduct 2 millions of point queries per second on my laptop. And it's not the fastest langu…

FFI was high priority for C# in the early days, when most meaningful .NET software was running on Windows and doing interop with win32. The runtime was designed to ensure that scenario would be low-overhead, and that legacy lives on in modern .NET.

FFI very much remains a priority today which can be seen with changes and migration to [LibraryImport], bespoke NativeAOT modes to produce native dynamically or statically linked libraries which expose C ABI functions with [UnmanagedCallersOnly] and now there is also a project to implement direct Swift library evolution ABI interop for improved support of iOS with MAUI as one of its main goals.

Re: I benchmarked six Go SQLite drivers

#59

Earlier quoted context omitted.

How come Zombiezen came out faster ? I’d expect the opposite

> How come Zombiezen came out faster ? I’d expect the opposite (OP here) Honestly, me too. Maybe it has to do with leaving out that database/sql driver layer. I guess it would need another round of pprof to find out the real reason.

That would be my guess as well. Please do let me know what you find, and feel free to open any issues or PRs.

Re: I benchmarked six Go SQLite drivers

#60
post #51

I'm the author or the WASM (+wazero) based github.com/ncruces/go-sqlite3. Happy to field questions. W.r.t. benchmark results. wazero's current compiler is somewhat naive, which may explain a large performance delta in CPU bound tests. A new compiler is in the works [1]. OTOH it seems interesting that in the (IO bound?) large test I'm doing better than modernc. I wonder why. I'll dig deeper into the results. [1]: http…

The performance difference was larger than I had expected. But this is good.

To fix a recent crash [1] that was happening due to a particular case of reentrancy, which only showed up when I implemented virtual tables and queried other tables to implement one (e.g.: Go calls sqlite3_step to execute a query, which calls Go because it's a query on virtual table, which calls sqlite3_step to scan another table) I introduced a performance regression.

The fix [2] was not to reuse some objects I was allocating once per connection. A mitigation for the regression was (very naive) caching [3].

TLDR: my caching is just not good enough. Simply caching more will go a long way (confirmed already by doubling cache size), but now that I have a good benchmark, I'll do better.

I expect to cut numbers for CPU bound tests in half due to this mishap.

So, thanks cvilsmeier!

[1]: https://github.com/ncruces/go-sqlite3/commit/a9e32fd3f0b9f39... [2]: https://github.com/ncruces/go-sqlite3/commit/d862f47d95d522f... [3]: https://github.com/ncruces/go-sqlite3/commit/9c562f5d8bf7436...

Post reply on HN