Skip to content

Switch over to modernc.org/sqlite as the SQLite driver #7882

Closed

Description

@unknwon

The CI has been running tests with this pure-Go SQLite driver for over two years now and no known issue has been identified.

The use of github.com/mattn/go-sqlite3 requires CGO which prevents us from cross-compile more release archives, and making the release process very cumbersome and easily outdated.

Before the switch over, we need to do a sanity test on SQLite file compatibility, i.e. create the SQLite file with github.com/mattn/go-sqlite3 and continue use with modernc.org/sqlite.

Ideally also backport to 0.13.

Activity

  1. added
    🗄 database
    on Dec 23, 2024
  2. added this to the 0.14.0 milestone on Dec 23, 2024
  3. self-assigned this
    on Dec 23, 2024
  4. GwynethLlewelyn commented on Jul 1, 2025

    @GwynethLlewelyn

    A wise choice indeed. Thanks for switching to the native Go package. I've been using it as well for a time, and I can't really tell the difference — except, of course, for making things far more portable across platforms!

    The benchmarks, however, clearly show that it's hard to beat a C library with native Go:

    https://pkg.go.dev/modernc.org/sqlite-bench#section-readme

    The benchmark was written by modernc, of course, so they cheated a bit. Apparently, their native Go code can beat CGo quite clearly in a scenario with multiple simultaneous reads — and when launching tons of goroutines to handle the load. I'm assuming that the issue here comes from limitations in how CGo needs to protect all those memory accesses for each goroutine (since the calls are made to unprotected C). By contrast, Go's native goroutines, running only native Go, are much more efficiently implemented — and this reflects quite positively on those benchmarks.

    I would therefore assume that someone running Gogs with SQLite in a scenario with hundreds or thousands of users, all reading/writing to large repositories with lots of files (and commits, etc...), will see a substantial improvement in their overall performance. By contrast, small repositories with few files and just a handful of users might get worse performance out of Gogs.

    That said, I can't really speak about my own case — I use MariaDB as the backend 🤣

  5. locked as resolved and limited conversation to collaborators on Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🗄 database

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions