#3699·ebiten

internal/graphicscommand: allocations on graphicscommand.(*drawTrianglesCommandPool).get

Author: inkelizCreated Sep 9, 2026Updated Sep 10, 2026
Labelsos:linuxos:macosperformance

Ebitengine Version

2.10

Operating System

  • Windows
  • macOS
  • Linux
  • FreeBSD
  • OpenBSD
  • Android
  • iOS
  • Nintendo Switch
  • PlayStation 5
  • Xbox
  • Web Browsers

Go Version (paste your go version output)

1.27.1

What steps will reproduce the problem?

It can be reproduced with a 'complex' scene with >1024 draw calls.

What is the expected result?

I expect Ebiten to avoid allocation, to avoid GC.

What happens instead?

The pprof reports a lot of allocations comming from:

#	0x1046462d7	github.com/hajimehoshi/ebiten/v2/internal/graphicscommand.(*commandQueue).EnqueueDrawTrianglesCommand+0x467		/Users/lucasrodrigues/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/internal/graphicscommand/commandqueue.go:192
#	0x1046479b7	github.com/hajimehoshi/ebiten/v2/internal/graphicscommand.(*commandQueueManager).enqueueDrawTrianglesCommand+0x147	/Users/lucasrodrigues/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/internal/graphicscommand/commandqueue.go:545
#	0x104648303	github.com/hajimehoshi/ebiten/v2/internal/graphicscommand.(*Image).DrawTriangles+0x173					/Users/lucasrodrigues/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/internal/graphicscommand/image.go:151
#	0x1046908ab	github.com/hajimehoshi/ebiten/v2/internal/atlas.(*Image).drawTriangles+0x54b						/Users/lucasrodrigues/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/internal/atlas/image.go:509
#	0x1046902c3	github.com/hajimehoshi/ebiten/v2/internal/atlas.(*Image).DrawTriangles+0x353						/Users/lucasrodrigues/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/internal/atlas/image.go:436
#	0x1046979cb	github.com/hajimehoshi/ebiten/v2/internal/buffered.(*Image).DrawTriangles+0x1cb						/Users/lucasrodrigues/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/internal/buffered/image.go:103
#	0x1046992cf	github.com/hajimehoshi/ebiten/v2/internal/mipmap.(*Mipmap).DrawTriangles+0x15f						/Users/lucasrodrigues/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/internal/mipmap/mipmap.go:94
#	0x104758427	github.com/hajimehoshi/ebiten/v2/internal/ui.(*Image).drawTriangles+0x177						/Users/lucasrodrigues/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/internal/ui/image.go:173
#	0x104758213	github.com/hajimehoshi/ebiten/v2/internal/ui.(*Image).DrawTriangles+0x153						/Users/lucasrodrigues/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/internal/ui/image.go:154
#	0x10477a67f	github.com/hajimehoshi/ebiten/v2.(*Image).DrawRectShader+0x5ef								/Users/lucasrodrigues/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/image.go:1139

Another issue comes from:

#	0x1048a6a67	slices.Grow[...]+0x3c7									/Users/lucasrodrigues/go/pkg/mod/golang.org/[email protected]/src/slices/slices.go:428
#	0x1048a69f4	github.com/hajimehoshi/ebiten/v2/vector.(*fillPathsState).addPath+0x354			/Users/lucasrodrigues/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/vector/fill.go:325
#	0x1048a60e7	github.com/hajimehoshi/ebiten/v2/vector.FillPath+0x307					/Users/lucasrodrigues/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/vector/fill.go:118
#	0x1048ae36b	github.com/hajimehoshi/ebiten/v2/vector.StrokePath+0xdb					/Users/lucasrodrigues/go/pkg/mod/github.com/hajimehoshi/ebiten/[email protected]/vector/util.go:360

However, I think that can be mitigated (by reusing the image).

Anything else you feel useful to add?

The current code is hardcoded for 1024:

https://github.com/hajimehoshi/ebiten/blob/c389f4ceb90f9bb2bd20a8cb474f5ea8f9139ebb/internal/graphicscommand/command.go#L56-L61

That seems to small and arbitrary, forcing allocations. I think it must be removed OR make it "public" so the responsibility of purging it is moved to the user/developer (not Ebiten).