From 3b0d477cfbe5bcb07f62e0869b21f849123cbb1e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 14 Dec 2025 03:31:39 +0000 Subject: [PATCH 1/3] Initial plan From aa1f4ad621291294329376ed4aef3ebb85316b50 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 14 Dec 2025 03:36:19 +0000 Subject: [PATCH 2/3] perf: streamline grid updates Co-authored-by: fffaraz <895678+fffaraz@users.noreply.github.com> --- Grid.hpp | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/Grid.hpp b/Grid.hpp index 83dc4a6..e7357ab 100644 --- a/Grid.hpp +++ b/Grid.hpp @@ -109,10 +109,32 @@ void Grid::updateP(const Grid& current, const Point& p) template void Grid::updateGrid(const Grid& current) { - for (int x = 0; x < SIZE; ++x) { + // Top row (requires bounds checks) + for (int y = 0; y < SIZE; ++y) { + updateP(current, { 0, y }); + } + + // Interior rows without redundant bounds checks + for (int x = 1; x < SIZE - 1; ++x) { + const bool* const rowAbove = current.grid_.data() + ((x - 1) * SIZE); + const bool* const row = current.grid_.data() + (x * SIZE); + const bool* const rowBelow = current.grid_.data() + ((x + 1) * SIZE); + bool* const destRow = grid_.data() + (x * SIZE); + + destRow[0] = gameOfLife(row[0], current.countLiveNeighbors({ x, 0 })); + for (int y = 1; y < SIZE - 1; ++y) { + const int live = rowAbove[y - 1] + rowAbove[y] + rowAbove[y + 1] + + row[y - 1] + row[y + 1] + + rowBelow[y - 1] + rowBelow[y] + rowBelow[y + 1]; + destRow[y] = gameOfLife(row[y], live); + } + destRow[SIZE - 1] = gameOfLife(row[SIZE - 1], current.countLiveNeighbors({ x, SIZE - 1 })); + } + + // Bottom row (requires bounds checks) + if constexpr (SIZE > 1) { for (int y = 0; y < SIZE; ++y) { - const Point p { x, y }; - updateP(current, p); + updateP(current, { SIZE - 1, y }); } } } @@ -126,10 +148,26 @@ void Grid::updateGrid(const Grid& current) // std::execution::par_unseq std::for_each(poolstl::par.on(threadPool), indices.begin(), indices.end(), [&](int x) { - for (int y = 0; y < SIZE; ++y) { - const Point p { x, y }; - updateP(current, p); + if (x == 0 || x == SIZE - 1) { + for (int y = 0; y < SIZE; ++y) { + updateP(current, { x, y }); + } + return; + } + + const bool* const rowAbove = current.grid_.data() + ((x - 1) * SIZE); + const bool* const row = current.grid_.data() + (x * SIZE); + const bool* const rowBelow = current.grid_.data() + ((x + 1) * SIZE); + bool* const destRow = grid_.data() + (x * SIZE); + + destRow[0] = gameOfLife(row[0], current.countLiveNeighbors({ x, 0 })); + for (int y = 1; y < SIZE - 1; ++y) { + const int live = rowAbove[y - 1] + rowAbove[y] + rowAbove[y + 1] + + row[y - 1] + row[y + 1] + + rowBelow[y - 1] + rowBelow[y] + rowBelow[y + 1]; + destRow[y] = gameOfLife(row[y], live); } + destRow[SIZE - 1] = gameOfLife(row[SIZE - 1], current.countLiveNeighbors({ x, SIZE - 1 })); }); } From c95e365b4095a62c7f3c19d92d5982436e321e9a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 14 Dec 2025 03:38:52 +0000 Subject: [PATCH 3/3] Optimize Game of Life grid update hot path Co-authored-by: fffaraz <895678+fffaraz@users.noreply.github.com> --- _codeql_detected_source_root | 1 + 1 file changed, 1 insertion(+) create mode 120000 _codeql_detected_source_root diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root new file mode 120000 index 0000000..945c9b4 --- /dev/null +++ b/_codeql_detected_source_root @@ -0,0 +1 @@ +. \ No newline at end of file