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 fda21d2bf..74d7c937e 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);
@@ -1926,7 +1928,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 adb94ac47..38e44562b 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);
@@ -564,6 +566,7 @@ QStringList MinecraftInstance::extraArguments(AuthSessionPtr session)
{
QString openALPath;
QString glfwPath;
+ QString jemallocPath;
if (settings()->get("UseNativeOpenAL").toBool()) {
openALPath = APPLICATION->m_detectedOpenALPath;
@@ -587,6 +590,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;
@@ -990,11 +1005,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 a2930aea1..631d237a3 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());
@@ -440,19 +449,24 @@ 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");
}
// 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