Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support loading libtcmalloc_minimal.dll for windows #16594

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions modules/initialize_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,21 @@ def configure_cors_middleware(app):
cors_options["allow_origin_regex"] = cmd_opts.cors_allow_origins_regex
app.add_middleware(CORSMiddleware, **cors_options)


def preload_malloc():
if os.name == 'nt':
import ctypes
# under windows we can't use LD_PRELOAD method but still we can load the libtcmalloc_minimal.dll using ctypes.cdll
# https://github.com/gperftools/gperftools/ (only gperftools's tcmalloc works with windows)
# build libtcmalloc_minimal.dll patch module and copy it into the top dir of webui

dir_path = os.path.dirname(__file__)
tcmallocdll = os.path.join(dir_path, "..", "libtcmalloc_minimal.dll")

if os.path.exists(tcmallocdll):
# load libtcmalloc_minimal.dll if it exists.
_tcmalloc_dll = ctypes.cdll.LoadLibrary(tcmallocdll)

return 'tcmalloc'

return None
4 changes: 4 additions & 0 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
startup_timer = timer.startup_timer
startup_timer.record("launcher")

malloc = initialize_util.preload_malloc()
if malloc is not None:
startup_timer.record(f"{malloc}")

initialize.imports()

initialize.check_versions()
Expand Down