perf(ui): skip the scroll-edge mask when no edge fades

ApplyScrollEdgeMask, which fades a scroll area's content at its top
and bottom edges, walked every vertex the area emitted on every frame
and tested both edges per vertex, even when the content fit without
scrolling and no vertex could ever be written. It now returns before
the walk when neither edge fades.

The fade maths moved unchanged into scroll_edge_fade.h and is tested
against the old inline expression, so rendering is identical. All six
callers benefit without an edit: the Overview address list, Mining's
recent blocks, Console, History, Explorer and Peers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 09:50:03 -05:00
co-authored by Claude Opus 5.5
parent 88fa13dd1a
commit bb973a1007
3 changed files with 89 additions and 14 deletions
+35
View File
@@ -59,6 +59,7 @@
#include "ui/windows/mining_benchmark.h"
#include "ui/windows/mining_pool_panel.h"
#include "ui/windows/mining_tab_helpers.h"
#include "ui/material/scroll_edge_fade.h"
#include "ui/node_status_banner.h"
#include "ui/staleness_badge.h"
#include "ui/notifications.h"
@@ -6383,6 +6384,9 @@ void testMiningEarningsCache()
EXPECT_FALSE(IntervalElapsed(1199, 200, 1000)); EXPECT_TRUE(IntervalElapsed(1200, 200, 1000));
}
// Local-midnight rollover with the tx list untouched (same tx_revision / count) and inside the 2 s max age:
// LocalDayStartMemo recomputes the day start as soon as `now` changes, the day start is part of the memo key,
// so "Today" empties into "Yesterday" at local midnight. Fixed POSIX TZ (UTC+3, no DST, no tzdata), restored.
void testMiningEarningsMidnightRollover()
{
#ifndef _WIN32
@@ -6418,6 +6422,36 @@ void testMiningEarningsMidnightRollover()
#endif
}
void testScrollEdgeFade()
{
using namespace dragonx::ui::material;
EXPECT_FALSE(ComputeScrollEdgeFade(0.0f, 0.0f).any()); // not scrollable
EXPECT_FALSE(ComputeScrollEdgeFade(1.0f, 0.0f).any()); // scrollY must be > 1
EXPECT_TRUE(ComputeScrollEdgeFade(100.0f, 100.0f).top); // at the bottom: top fade only
EXPECT_FALSE(ComputeScrollEdgeFade(100.0f, 100.0f).bottom);
EXPECT_TRUE(ComputeScrollEdgeFade(0.0f, 200.0f).bottom); // top of a scrollable list: bottom fade only
EXPECT_FALSE(ComputeScrollEdgeFade(0.0f, 200.0f).top);
EXPECT_FALSE(ComputeScrollEdgeFade(199.5f, 200.0f).bottom); // within 1 px of the bottom
// Bit-equivalence with the former inline maths over a grid, and the early-out invariant.
auto oldAlpha = [](float scrollY, float scrollMaxY, float y, float topEdge, float bottomEdge, float fz) {
float alpha = 1.0f;
if (scrollY > 1.0f) { float d = y - topEdge; if (d < fz) alpha = std::min(alpha, std::max(0.0f, d / fz)); }
if (scrollMaxY > 0 && scrollY < scrollMaxY - 1.0f) {
float d = bottomEdge - y; if (d < fz) alpha = std::min(alpha, std::max(0.0f, d / fz));
}
return alpha;
};
const float states[][2] = {{0, 0}, {0, 300}, {0.5f, 300}, {1.0f, 300}, {1.5f, 300}, {150, 300},
{298.9f, 300}, {299.5f, 300}, {300, 300}, {50, 0}};
for (const auto& s : states)
for (float y = -20.0f; y <= 420.0f; y += 7.0f) {
const ScrollEdgeFade f = ComputeScrollEdgeFade(s[0], s[1]);
const float a = ScrollEdgeAlpha(f, y, 10.0f, 360.0f, 40.0f);
EXPECT_NEAR(a, oldAlpha(s[0], s[1], y, 10.0f, 360.0f, 40.0f), 0.0);
if (!f.any()) EXPECT_NEAR(a, 1.0, 0.0);
}
}
void testMiningBenchmarkModel()
{
dragonx::ui::ThreadBenchmark benchmark;
@@ -14748,6 +14782,7 @@ int main()
testMiningEarningsCore();
testMiningEarningsCache();
testMiningEarningsMidnightRollover();
testScrollEdgeFade();
testBalanceAddressListModel();
testExplorerBlockCache();
testTransactionHistoryCache();