Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/igox/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tool github.com/goplus/ixgo/cmd/qexp

require (
github.com/goplus/builder/tools/ai v0.0.0-20251014030930-ac405dbe65e9
github.com/goplus/ixgo v0.57.0
github.com/goplus/ixgo v0.59.1-0.20251119042043-c643e44b5f5c
github.com/goplus/mod v0.17.1
github.com/goplus/reflectx v1.5.0
github.com/goplus/spx/v2 v2.0.0-pre.20
Expand Down
4 changes: 2 additions & 2 deletions cmd/igox/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ github.com/goplus/builder/tools/ai v0.0.0-20251014030930-ac405dbe65e9 h1:p15bf31
github.com/goplus/builder/tools/ai v0.0.0-20251014030930-ac405dbe65e9/go.mod h1:jhQQ+yC3iLd6/GGnRleF+536nnjoLm5qvFwrNJvSezo=
github.com/goplus/gogen v1.19.5 h1:YWPwpRA1PusPhptv9jKg/XiN+AQGiAD9r6I86mJ3lR4=
github.com/goplus/gogen v1.19.5/go.mod h1:owX2e1EyU5WD+Nm6oH2m/GXjLdlBYcwkLO4wN8HHXZI=
github.com/goplus/ixgo v0.57.0 h1:qpz1ofixBKdPIdYPzcI9lpKoUcKzj16WpjVA3hJuLoI=
github.com/goplus/ixgo v0.57.0/go.mod h1:gA6EKc46iWR6kX4bCYiKnEV8QtpxxvGcDRyT+5vO/ic=
github.com/goplus/ixgo v0.59.1-0.20251119042043-c643e44b5f5c h1:Nr6eBp1eJAtFA3NfssLZbV8bmjIc+TZK3pXKiUfI2Lc=
github.com/goplus/ixgo v0.59.1-0.20251119042043-c643e44b5f5c/go.mod h1:oreqPAcYBb/sEx6oCl7/kiCawfHQm08e6OAwYVi5aMM=
github.com/goplus/mod v0.17.1 h1:ITovxDcc5zbURV/Wrp3/SBsYLgC1KrxY6pq1zMM2V94=
github.com/goplus/mod v0.17.1/go.mod h1:iXEszBKqi38BAyQApBPyQeurLHmQN34YMgC2ZNdap50=
github.com/goplus/reflectx v1.5.0 h1:d6THLWzrQJCIAnNzyXJDA7J1sxj8ELzKH+Wj17X/dtE=
Expand Down
22 changes: 16 additions & 6 deletions cmd/igox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ var defaultRunner *SpxRunner = NewSpxRunner()

// SpxRunner encapsulates the build and run functionality for SPX code.
type SpxRunner struct {
ctx *ixgo.Context
entry *interpCacheEntry
debug bool
ctx *ixgo.Context
buildCtx *xgobuild.Context
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused field: The buildCtx field is declared but never assigned or used anywhere in the code. This appears to be leftover from incomplete refactoring.

Recommendation: Either remove this field entirely, or if it's intended for future use, add a comment explaining its purpose. If it should store the xgoCtx created on line 210, the assignment is missing.

entry *interpCacheEntry
debug bool
}

// interpCacheEntry stores the build result.
Expand Down Expand Up @@ -206,10 +207,15 @@ func Gopt_Player_Gopx_OnCmd[T any](p *Player, handler func(cmd T) error) {
return nil
}

return &SpxRunner{
xgoCtx := xgobuild.NewContext(ctx)
xgoCtx.Importer = ctx.Importer
Comment on lines +210 to +211
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variable: The xgoCtx is created and configured but never used. It's not assigned to the buildCtx field or used elsewhere.

Recommendation: Either:

  1. Remove these lines if the context isn't needed, OR
  2. Assign it to runer.buildCtx = xgoCtx if that was the intent

runer := &SpxRunner{
ctx: ctx,
debug: false,
}

runer.prebuildSSA()
return runer
Comment on lines +210 to +218

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

There are a few issues in this block that need to be addressed:

  1. The variable xgoCtx is declared but never used, which will cause a compilation error.
  2. The newly added field buildCtx on SpxRunner is not initialized. It seems xgoCtx was intended to be assigned to it.
  3. There's a typo in the variable name runer; it should be runner.

Here is a suggestion to fix these issues.

Suggested change
xgoCtx := xgobuild.NewContext(ctx)
xgoCtx.Importer = ctx.Importer
runer := &SpxRunner{
ctx: ctx,
debug: false,
}
runer.prebuildSSA()
return runer
xgoCtx := xgobuild.NewContext(ctx)
xgoCtx.Importer = ctx.Importer
runner := &SpxRunner{
ctx: ctx,
buildCtx: xgoCtx,
debug: false,
}
runner.prebuildSSA()
return runner

}

// Build builds the SPX code from the provided files object.
Expand Down Expand Up @@ -318,13 +324,17 @@ func (r *SpxRunner) Run(this js.Value, args []js.Value) any {

// Release releases resources held by the SpxRunner.
func (r *SpxRunner) Release() {
// Clear context
r.ctx.RunContext = nil
if r.entry != nil && r.entry.interp != nil {
r.entry.interp.UnsafeRelease()
r.entry.fs.Close()
r.entry = nil
}

r.prebuildSSA()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance concern: Calling prebuildSSA() in the Release() method adds compilation overhead to the cleanup path. This appears to be a performance anti-pattern.

Analysis:

  • SSA prebuilding is CPU-intensive compilation work for two large packages
  • Calling it during cleanup adds latency to every build-release cycle
  • The prebuilt SSA provides no immediate benefit after releasing resources

Recommendation: Remove this call. SSA prebuilding should only happen once during initialization (as it does on line 217), not during cleanup. If re-prebuilding is needed, it should be done lazily before the next build operation, not during release.

}

func (r *SpxRunner) prebuildSSA() {
r.ctx.PrebuildSSA("github.com/goplus/spx/v2", "github.com/goplus/builder/tools/ai")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The package paths "github.com/goplus/spx/v2" and "github.com/goplus/builder/tools/ai" are hardcoded here. These 'magic strings' are also used elsewhere in the file (e.g., for RegisterPatch). To improve maintainability and reduce the risk of typos, consider defining these paths as package-level constants and reusing them.

}
Comment on lines +336 to 338
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing documentation: This new method lacks documentation explaining:

  • What SSA prebuilding does and why it improves performance
  • Why these specific packages are prebuilt
  • When this method is called in the lifecycle

Suggestion:

// prebuildSSA prebuilds SSA (Static Single Assignment) form for frequently-used packages
// to improve interpreter startup performance. This caches the compiled SSA representation
// of spx and ai packages, reducing build overhead for subsequent interpreter operations.
func (r *SpxRunner) prebuildSSA() {
    r.ctx.PrebuildSSA("github.com/goplus/spx/v2", "github.com/goplus/builder/tools/ai")
}


func logWithCallerInfo(msg string, frame *ixgo.Frame) {
Expand Down
Loading