Hacker News new | ask | show | jobs
by summarity 2525 days ago
Sqlite has been rewritten in both Go and C#.

It's really not that hard. The code is clearly documented and everything works in roughly the same way. Easily achievable by a single developer in a few months.

Sqlite code is emulating classes with structs and methods (they're even called classes in the code). This it's pretty easy to translate into languages with reference and struct support.

Memory allocation is separated into an allocation provider, which is easy to implement in GC languages (just create the struct requested).

The parser and VM opcode file is tricky. The opcodes are parsed from comments in one big file. I'm not a fan of that. But once generated for a particular version, pretty easy to translate.

Testing is another can of worms. Translating the exact version of Tcl, too is the best course of action. This is required to run and pass the (hundreds of thousands of) base line tests. Other correctness tests (in sqlite because of branch coverage requirements for aircraft software) are harder to translate. The prerelease burn in test is also not publicly available.

Preprocessor directives are not used as macros. Rather they are used to enable features. In a port, you can for example choose to exclude WAL or specific optimizations. FTS can be left out if not needed. The different lock implementations can be deferred to the stdlib.

If you interested in the perf overhead, here's a small benchmark of a C# implementation I maintain:

https://drive.google.com/file/d/11Bgfh1WgEreDenosoEdWkYAOb6u...

1 comments

Can you point to the pure Go re-implementation of Sqlite? I was looking for such a thing but never found it. Instead I had to go with a k/v store like Bolt.
That's not it. It was a GitLab project, but searching for that is pretty difficult. I'll edit this comment if i find it.

Edit: Here it is: https://gitlab.com/cznic/sqlite