Compare commits

...

3 commits

Author SHA1 Message Date
kim 15d856aa39
Merge 3464b39d39 into 9f6a1f7e79 2024-10-17 18:33:16 +02:00
Daenney 9f6a1f7e79
[chore] Set some additional git attributes (#3454)
* .go files are now tagged with diff=go for better diffs
* go.sum is tagged with generated which suppresses the diff
* go.sum is tagged with merge=ours to reduce merge conflicts

go.mod isn't tagged with generated since it's useful to see it on
dependency bump PRs.
2024-10-17 16:24:03 +00:00
kim 3464b39d39 this sets the memory limit for ncruces/go-sqlite3 according to ptr size (i.e. platform 32 / 64bit) 2024-10-14 23:59:47 +01:00
2 changed files with 34 additions and 1 deletions

4
.gitattributes vendored
View file

@ -1 +1,3 @@
/vendor/ linguist-generated *.go diff=golang
go.sum linguist-generated merge=ours
/vendor/ linguist-generated

View file

@ -23,13 +23,44 @@
"context" "context"
"database/sql/driver" "database/sql/driver"
"codeberg.org/gruf/go-bytesize"
"github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/tetratelabs/wazero"
"github.com/ncruces/go-sqlite3"
sqlite3driver "github.com/ncruces/go-sqlite3/driver" sqlite3driver "github.com/ncruces/go-sqlite3/driver"
_ "github.com/ncruces/go-sqlite3/embed" // embed wasm binary _ "github.com/ncruces/go-sqlite3/embed" // embed wasm binary
_ "github.com/ncruces/go-sqlite3/vfs/memdb" // include memdb vfs _ "github.com/ncruces/go-sqlite3/vfs/memdb" // include memdb vfs
) )
func init() {
// Initialize WASM runtime config.
cfg := wazero.NewRuntimeConfig()
// The size of a page in WASM.
const pageSize = uint32(^uint16(0))
// The following check is compile-time:
//
// Size of a pointer on this platform,
// i.e. are we running on 32 / 64 bit.
//
// See: https://github.com/ncruces/go-sqlite3/issues/168#issuecomment-2412429221
const ptrsz = 32 << (^uintptr(0) >> 63)
switch ptrsz {
case 32:
const memoryLimit = uint32(32*bytesize.MiB) / pageSize
cfg = cfg.WithMemoryLimitPages(memoryLimit)
case 64:
const memoryLimit = uint32(256*bytesize.MiB) / pageSize
cfg = cfg.WithMemoryLimitPages(memoryLimit)
}
// Set runtime config before
// initialize func gets called.
sqlite3.RuntimeConfig = cfg
}
// Driver is our own wrapper around the // Driver is our own wrapper around the
// driver.SQLite{} type in order to wrap // driver.SQLite{} type in order to wrap
// further SQL types with our own // further SQL types with our own