From a5117a9c333827a82d5a9fdd95ee9bc4da5504c2 Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Sat, 1 Aug 2026 13:32:29 +0200 Subject: [PATCH] build(windows): Enable segment heap if possible (#7142) With Visual Studio 2026 18.6, Microsoft included a script to easily enable the segment heap for apps ([blog](https://devblogs.microsoft.com/cppblog/segment-heap-support-for-c-projects-in-visual-studio/)). The segment heap was already available for some years, but it hasn't been enabled by default. With the provided script we can add a manifest to enable it. In my basic testing it reduced the memory usage from ~75MiB to ~70MiB with one tab and 4 messages. So it should be a free win for us. Reviewed-by: pajlada --- CMakeLists.txt | 4 ++++ cmake/EnableSegmentHeap.cmake | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 cmake/EnableSegmentHeap.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 036113278..165b80d88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,10 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ) +if(WIN32 AND NOT MINGW) + include(EnableSegmentHeap) +endif() + option(BUILD_APP "Build Chatterino" ON) option(BUILD_TESTS "Build the tests for Chatterino" OFF) option(BUILD_BENCHMARKS "Build the benchmarks for Chatterino" OFF) diff --git a/cmake/EnableSegmentHeap.cmake b/cmake/EnableSegmentHeap.cmake new file mode 100644 index 000000000..31373a734 --- /dev/null +++ b/cmake/EnableSegmentHeap.cmake @@ -0,0 +1,17 @@ +# SPDX-FileCopyrightText: 2026 Contributors to Chatterino +# +# SPDX-License-Identifier: CC0-1.0 + +if(NOT DEFINED ENV{VSINSTALLDIR}) + message(WARNING "Missing VSINSTALLDIR environment variable - not enabling segment heap.") + return() +endif() + +set(segment_heap_path "$ENV{VSINSTALLDIR}Common7/IDE/CommonExtensions/Microsoft/CMake/cmake/Microsoft/SegmentHeap.cmake") +if (NOT EXISTS "${segment_heap_path}") + message(STATUS "Missing '${segment_heap_path}'. Segment heap will be disabled - consider updating Visual Studio.") + return() +endif() + +message(STATUS "Including segment heap script from '${segment_heap_path}'.") +include("${segment_heap_path}")