hajimehoshi / ebiten

Ebitengine - A dead simple 2D game engine for Go
https://ebitengine.org
Apache License 2.0
11.12k stars 664 forks source link

Add a debug.IsDebug check before splitting strings #3134

Closed gabstv closed 1 month ago

gabstv commented 1 month ago

What issue is this addressing?

--

What type of issue is this addressing?

feature

What this PR does | solves

Since debug.IsDebug is a constant, by putting the strings.Cut calls inside the check this makes the (*commandqueue).flush method faster when Ebitengine is compiled without the debug build tag.

Without the if debug.IsDebug check, unnecessary allocations occur (since the logger is a noop logger when debug is disabled): Screenshot_20241018_084146

GC Details after the change: Screenshot_20241018_084204

This happens because Go knows that IsDebug is a constant (and the compiler will optimize this away on production builds).