From 0811513c9d2da471fc9d509880a2d5ca57ee8a17 Mon Sep 17 00:00:00 2001 From: 4DBug Date: Wed, 21 Oct 2026 02:26:50 -0500 Subject: [PATCH] BeginPlot: resolve the cached axis colours once per plot (X1) and copy them to the other five axes instead of resolving the auto colour chain per axis (bench implot scene, items stubbed: 0.457 -> 0.422 ms; draw data unchanged) --- ImPlot.lua | 13 +++++++++++-- love/ImPlot.lua | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ImPlot.lua b/ImPlot.lua index 088e953..2069c9b 100644 --- a/ImPlot.lua +++ b/ImPlot.lua @@ -3611,9 +3611,18 @@ return function(G) end -- reset axes + -- [Luau] the cached colours do not depend on the axis: resolved once (X1) and copied to the other axes + -- (resolving the auto colours walks the auto colour chain and allocates: ~1.5 us per axis per frame) + local a0 = plot.Axes[0] for i = 0, ImAxis.COUNT - 1 do - plot.Axes[i]:Reset() - UpdateAxisColors(plot.Axes[i]) + local axis = plot.Axes[i] + axis:Reset() + if i == 0 then + UpdateAxisColors(axis) + else + axis.ColorMaj, axis.ColorMin, axis.ColorTick, axis.ColorTxt = a0.ColorMaj, a0.ColorMin, a0.ColorTick, a0.ColorTxt + axis.ColorBg, axis.ColorHov, axis.ColorAct = a0.ColorBg, a0.ColorHov, a0.ColorAct + end end -- ensure first axes enabled plot.Axes[ImAxis.X1].Enabled = true diff --git a/love/ImPlot.lua b/love/ImPlot.lua index 8aa93c9..a338975 100644 --- a/love/ImPlot.lua +++ b/love/ImPlot.lua @@ -3613,9 +3613,18 @@ end plot.Selected = true end -- reset axes + -- [Luau] the cached colours do not depend on the axis: resolved once (X1) and copied to the other axes + -- (resolving the auto colours walks the auto colour chain and allocates: ~1.5 us per axis per frame) + local a0 = plot.Axes[0] for i = 0, ImAxis.COUNT - 1 do - plot.Axes[i]:Reset() - UpdateAxisColors(plot.Axes[i]) + local axis = plot.Axes[i] + axis:Reset() + if i == 0 then + UpdateAxisColors(axis) + else + axis.ColorMaj, axis.ColorMin, axis.ColorTick, axis.ColorTxt = a0.ColorMaj, a0.ColorMin, a0.ColorTick, a0.ColorTxt + axis.ColorBg, axis.ColorHov, axis.ColorAct = a0.ColorBg, a0.ColorHov, a0.ColorAct + end end -- ensure first axes enabled plot.Axes[ImAxis.X1].Enabled = true