From 929c914dc206b2d894a9d164731eebc45ca3e8d4 Mon Sep 17 00:00:00 2001 From: Tuwum Date: Mon, 7 Sep 2026 16:29:06 +0400 Subject: [PATCH 1/2] Add system jemalloc support Signed-off-by: Tuwum --- CMakeLists.txt | 3 ++ buildconfig/BuildConfig.h | 1 + launcher/Application.cpp | 5 ++- launcher/Application.h | 1 + launcher/minecraft/MinecraftInstance.cpp | 20 ++++++++- .../ui/widgets/MinecraftSettingsWidget.cpp | 13 ++++++ .../ui/widgets/MinecraftSettingsWidget.ui | 42 +++++++++++++++++++ 7 files changed, 83 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e2bb23125..e3a4aeb81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,12 +244,15 @@ option(Launcher_ENABLE_JAVA_DOWNLOADER "Build the java downloader feature" ${Lau if(UNIX AND APPLE) set(Launcher_GLFW_LIBRARY_NAME "libglfw.dylib" CACHE STRING "Name of native glfw library") set(Launcher_OPENAL_LIBRARY_NAME "libopenal.dylib" CACHE STRING "Name of native openal library") + set(Launcher_JEMALLOC_LIBRARY_NAME "libjemalloc.dylib" CACHE STRING "Name of native jemalloc library") elseif(UNIX) set(Launcher_GLFW_LIBRARY_NAME "libglfw.so" CACHE STRING "Name of native glfw library") set(Launcher_OPENAL_LIBRARY_NAME "libopenal.so" CACHE STRING "Name of native openal library") + set(Launcher_JEMALLOC_LIBRARY_NAME "libjemalloc.so" CACHE STRING "Name of native jemalloc library") elseif(WIN32) set(Launcher_GLFW_LIBRARY_NAME "glfw.dll" CACHE STRING "Name of native glfw library") set(Launcher_OPENAL_LIBRARY_NAME "OpenAL.dll" CACHE STRING "Name of native openal library") + set(Launcher_JEMALLOC_LIBRARY_NAME "jemalloc.dll" CACHE STRING "Name of native jemalloc library") endif() # API Keys diff --git a/buildconfig/BuildConfig.h b/buildconfig/BuildConfig.h index 229d4541b..5f7b779d8 100644 --- a/buildconfig/BuildConfig.h +++ b/buildconfig/BuildConfig.h @@ -177,6 +177,7 @@ class Config { QString GLFW_LIBRARY_NAME; QString OPENAL_LIBRARY_NAME; + QString JEMALLOC_LIBRARY_NAME; QString BUG_TRACKER_URL; QString TRANSLATIONS_URL; diff --git a/launcher/Application.cpp b/launcher/Application.cpp index ac6ce4c79..c2870f08c 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -821,6 +821,8 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) m_settings->registerSetting("CustomOpenALPath", ""); m_settings->registerSetting("UseNativeGLFW", false); m_settings->registerSetting("CustomGLFWPath", ""); + m_settings->registerSetting("UseNativeJemalloc", false); + m_settings->registerSetting("CustomJemallocPath", ""); // Performance related options m_settings->registerSetting("EnableFeralGamemode", false); @@ -1932,7 +1934,8 @@ void Application::detectLibraries() #ifdef Q_OS_LINUX m_detectedGLFWPath = LibraryUtils::find(BuildConfig.GLFW_LIBRARY_NAME); m_detectedOpenALPath = LibraryUtils::find(BuildConfig.OPENAL_LIBRARY_NAME); - qDebug() << "Detected native libraries:" << m_detectedGLFWPath << m_detectedOpenALPath; + m_detectedJemallocPath = LibraryUtils::find(BuildConfig.JEMALLOC_LIBRARY_NAME); + qDebug() << "Detected native libraries:" << m_detectedGLFWPath << m_detectedOpenALPath << m_detectedJemallocPath; #endif } diff --git a/launcher/Application.h b/launcher/Application.h index c26cbe4a7..6666c0992 100644 --- a/launcher/Application.h +++ b/launcher/Application.h @@ -313,6 +313,7 @@ class Application : public QApplication { public: QString m_detectedGLFWPath; QString m_detectedOpenALPath; + QString m_detectedJemallocPath; QString m_instanceIdToLaunch; QString m_serverToJoin; QString m_worldToJoin; diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index dcc11b4be..079d1d750 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -225,6 +225,8 @@ void MinecraftInstance::loadSpecificSettings() m_settings->registerOverride(global_settings->getSetting("CustomOpenALPath"), nativeLibraryWorkaroundsOverride); m_settings->registerOverride(global_settings->getSetting("UseNativeGLFW"), nativeLibraryWorkaroundsOverride); m_settings->registerOverride(global_settings->getSetting("CustomGLFWPath"), nativeLibraryWorkaroundsOverride); + m_settings->registerOverride(global_settings->getSetting("UseNativeJemalloc"), nativeLibraryWorkaroundsOverride); + m_settings->registerOverride(global_settings->getSetting("CustomJemallocPath"), nativeLibraryWorkaroundsOverride); // Performance related options auto performanceOverride = m_settings->registerSetting("OverridePerformance", false); @@ -562,6 +564,7 @@ QStringList MinecraftInstance::extraArguments(AuthSessionPtr session) { QString openALPath; QString glfwPath; + QString jemallocPath; if (settings()->get("UseNativeOpenAL").toBool()) { openALPath = APPLICATION->m_detectedOpenALPath; @@ -585,6 +588,18 @@ QStringList MinecraftInstance::extraArguments(AuthSessionPtr session) if (!glfwPath.isEmpty() && glfwInfo.exists()) list.append("-Dorg.lwjgl.glfw.libname=" + glfwInfo.absoluteFilePath()); } + + if (settings()->get("UseNativeJemalloc").toBool()) { + jemallocPath = APPLICATION->m_detectedJemallocPath; + auto customPath = settings()->get("CustomJemallocPath").toString(); + if (!customPath.isEmpty()) + jemallocPath = customPath; + + QFileInfo jemallocInfo(jemallocPath); + + if (!jemallocPath.isEmpty() && jemallocInfo.exists()) + list.append("-Dorg.lwjgl.system.jemalloc.libname=" + jemallocInfo.absoluteFilePath()); + } } return list; @@ -988,11 +1003,14 @@ QStringList MinecraftInstance::verboseDescription(AuthSessionPtr session, Minecr auto settings = this->settings(); bool nativeOpenAL = settings->get("UseNativeOpenAL").toBool(); bool nativeGLFW = settings->get("UseNativeGLFW").toBool(); - if (nativeOpenAL || nativeGLFW) { + bool nativeJemalloc = settings->get("UseNativeJemalloc").toBool(); + if (nativeOpenAL || nativeGLFW || nativeJemalloc) { if (nativeOpenAL) out << "Using system OpenAL."; if (nativeGLFW) out << "Using system GLFW."; + if (nativeJemalloc) + out << "Using system Jemalloc."; out << emptyLine; } diff --git a/launcher/ui/widgets/MinecraftSettingsWidget.cpp b/launcher/ui/widgets/MinecraftSettingsWidget.cpp index 1b8576dcc..8c5ab40bc 100644 --- a/launcher/ui/widgets/MinecraftSettingsWidget.cpp +++ b/launcher/ui/widgets/MinecraftSettingsWidget.cpp @@ -156,6 +156,8 @@ MinecraftSettingsWidget::MinecraftSettingsWidget(MinecraftInstance* instance, QW connect(m_ui->useNativeOpenALCheck, &QAbstractButton::toggled, m_ui->lineEditOpenALPath, &QWidget::setEnabled); connect(m_ui->useNativeGLFWCheck, &QAbstractButton::toggled, m_ui->lineEditGLFWPath, &QWidget::setEnabled); + connect(m_ui->useNativeJemallocCheck, &QAbstractButton::toggled, m_ui->lineEditJemallocPath, &QWidget::setEnabled); + connect(m_ui->injectorImplCombo, &QComboBox::currentIndexChanged, this, [this] { resetInjectorVersion(); }); @@ -240,6 +242,13 @@ void MinecraftSettingsWidget::loadSettings() #else m_ui->lineEditOpenALPath->setPlaceholderText(tr("Path to %1 library file").arg(BuildConfig.OPENAL_LIBRARY_NAME)); #endif + m_ui->useNativeJemallocCheck->setChecked(settings->get("UseNativeJemalloc").toBool()); + m_ui->lineEditJemallocPath->setText(settings->get("CustomJemallocPath").toString()); +#ifdef Q_OS_LINUX + m_ui->lineEditJemallocPath->setPlaceholderText(APPLICATION->m_detectedJemallocPath); +#else + m_ui->lineEditJemallocPath->setPlaceholderText(tr("Path to %1 library file").arg(BuildConfig.JEMALLOC_LIBRARY_NAME)); +#endif // Performance m_ui->perfomanceGroupBox->setChecked(m_instance == nullptr || settings->get("OverridePerformance").toBool()); @@ -451,11 +460,15 @@ void MinecraftSettingsWidget::saveSettings() settings->set("CustomGLFWPath", m_ui->lineEditGLFWPath->text()); settings->set("UseNativeOpenAL", m_ui->useNativeOpenALCheck->isChecked()); settings->set("CustomOpenALPath", m_ui->lineEditOpenALPath->text()); + settings->set("UseNativeJemalloc", m_ui->useNativeJemallocCheck->isChecked()); + settings->set("CustomJemallocPath", m_ui->lineEditJemallocPath->text()); } else { settings->reset("UseNativeGLFW"); settings->reset("CustomGLFWPath"); settings->reset("UseNativeOpenAL"); settings->reset("CustomOpenALPath"); + settings->reset("UseNativeJemalloc"); + settings->reset("CustomJemallocPath"); } // Performance diff --git a/launcher/ui/widgets/MinecraftSettingsWidget.ui b/launcher/ui/widgets/MinecraftSettingsWidget.ui index e3eef16e2..392c8b1cc 100644 --- a/launcher/ui/widgets/MinecraftSettingsWidget.ui +++ b/launcher/ui/widgets/MinecraftSettingsWidget.ui @@ -858,6 +858,32 @@ + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 0 + 6 + + + + + + + + &Jemalloc library path: + + + lineEditJemallocPath + + + @@ -886,6 +912,20 @@ + + + + Use system installation of Jemalloc + + + + + + + false + + + @@ -1065,6 +1105,8 @@ lineEditGLFWPath useNativeOpenALCheck lineEditOpenALPath + useNativeJemallocCheck + lineEditJemallocPath enableFeralGamemodeCheck enableMangoHud useDiscreteGpuCheck From 37cc7965226ffbcb7459d66da6eed6b73ecb35b4 Mon Sep 17 00:00:00 2001 From: Tuwum Date: Thu, 10 Sep 2026 19:06:40 +0400 Subject: [PATCH 2/2] Fix indentation Signed-off-by: Tuwum --- .../ui/widgets/MinecraftSettingsWidget.cpp | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/launcher/ui/widgets/MinecraftSettingsWidget.cpp b/launcher/ui/widgets/MinecraftSettingsWidget.cpp index 6adec8791..631d237a3 100644 --- a/launcher/ui/widgets/MinecraftSettingsWidget.cpp +++ b/launcher/ui/widgets/MinecraftSettingsWidget.cpp @@ -449,24 +449,25 @@ void MinecraftSettingsWidget::saveSettings() // Workarounds bool workarounds = m_instance == nullptr || m_ui->nativeWorkaroundsGroupBox->isChecked(); - if (m_instance != nullptr) + if (m_instance != nullptr) { settings->set("OverrideNativeWorkarounds", workarounds); + } - if (workarounds) { - settings->set("UseNativeGLFW", m_ui->useNativeGLFWCheck->isChecked()); - settings->set("CustomGLFWPath", m_ui->lineEditGLFWPath->text()); - settings->set("UseNativeOpenAL", m_ui->useNativeOpenALCheck->isChecked()); - settings->set("CustomOpenALPath", m_ui->lineEditOpenALPath->text()); - settings->set("UseNativeJemalloc", m_ui->useNativeJemallocCheck->isChecked()); - settings->set("CustomJemallocPath", m_ui->lineEditJemallocPath->text()); - } else { - settings->reset("UseNativeGLFW"); - settings->reset("CustomGLFWPath"); - settings->reset("UseNativeOpenAL"); - settings->reset("CustomOpenALPath"); - settings->reset("UseNativeJemalloc"); - settings->reset("CustomJemallocPath"); - } + if (workarounds) { + settings->set("UseNativeGLFW", m_ui->useNativeGLFWCheck->isChecked()); + settings->set("CustomGLFWPath", m_ui->lineEditGLFWPath->text()); + settings->set("UseNativeOpenAL", m_ui->useNativeOpenALCheck->isChecked()); + settings->set("CustomOpenALPath", m_ui->lineEditOpenALPath->text()); + settings->set("UseNativeJemalloc", m_ui->useNativeJemallocCheck->isChecked()); + settings->set("CustomJemallocPath", m_ui->lineEditJemallocPath->text()); + } else { + settings->reset("UseNativeGLFW"); + settings->reset("CustomGLFWPath"); + settings->reset("UseNativeOpenAL"); + settings->reset("CustomOpenALPath"); + settings->reset("UseNativeJemalloc"); + settings->reset("CustomJemallocPath"); + } // Performance bool performance = m_instance == nullptr || m_ui->perfomanceGroupBox->isChecked();