Skip to content

Commit

Permalink
move WASM compilation stage much later in server init to reduce memor…
Browse files Browse the repository at this point in the history
…y usage during db migrations (#3242)
  • Loading branch information
NyaaaWhatsUpDoc authored Aug 26, 2024
1 parent 28d57d1 commit f4d69db
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions cmd/gotosocial/action/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (

"github.com/KimMachineGun/automemlimit/memlimit"
"github.com/gin-gonic/gin"
"github.com/ncruces/go-sqlite3"
"github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action"
"github.com/superseriousbusiness/gotosocial/internal/api"
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
Expand Down Expand Up @@ -74,13 +73,6 @@ var Start action.GTSAction = func(ctx context.Context) error {
// to match container limits.
setLimits(ctx)

// Compile WASM modules ahead of first use
// to prevent unexpected initial slowdowns.
log.Info(ctx, "precompiling WebAssembly")
if err := precompileWASM(ctx); err != nil {
return err
}

var (
// Define necessary core variables
// before anything so we can prepare
Expand Down Expand Up @@ -203,6 +195,17 @@ var Start action.GTSAction = func(ctx context.Context) error {
TLSInsecureSkipVerify: config.GetHTTPClientTLSInsecureSkipVerify(),
})

// Compile WASM modules ahead of first use
// to prevent unexpected initial slowdowns.
//
// Note that this can take a bit of memory
// and processing so we perform this much
// later after any database migrations.
log.Info(ctx, "compiling WebAssembly")
if err := compileWASM(ctx); err != nil {
return err
}

// Build handlers used in later initializations.
mediaManager := media.NewManager(state)
oauthServer := oauth.New(ctx, dbService)
Expand Down Expand Up @@ -491,11 +494,7 @@ func setLimits(ctx context.Context) {
}
}

func precompileWASM(ctx context.Context) error {
if err := sqlite3.Initialize(); err != nil {
return gtserror.Newf("error compiling sqlite3: %w", err)
}

func compileWASM(ctx context.Context) error {
// Use admin-set ffmpeg pool size, and fall
// back to GOMAXPROCS if number 0 or less.
ffPoolSize := config.GetMediaFfmpegPoolSize()
Expand Down

0 comments on commit f4d69db

Please sign in to comment.