Skip to content

Commit 7a91722

Browse files
committed
support loading libtcmalloc_minimal.dll for windows
1 parent 5865da2 commit 7a91722

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

modules/initialize_util.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,21 @@ def configure_cors_middleware(app):
213213
cors_options["allow_origin_regex"] = cmd_opts.cors_allow_origins_regex
214214
app.add_middleware(CORSMiddleware, **cors_options)
215215

216+
217+
def preload_malloc():
218+
if os.name == 'nt':
219+
import ctypes
220+
# under windows we can't use LD_PRELOAD method but still we can load the libtcmalloc_minimal.dll using ctypes.cdll
221+
# https://github.com/gperftools/gperftools/ (only gperftools's tcmalloc works with windows)
222+
# build libtcmalloc_minimal.dll patch module and copy it into the top dir of webui
223+
224+
dir_path = os.path.dirname(__file__)
225+
tcmallocdll = os.path.join(dir_path, "..", "libtcmalloc_minimal.dll")
226+
227+
if os.path.exists(tcmallocdll):
228+
# load libtcmalloc_minimal.dll if it exists.
229+
_tcmalloc_dll = ctypes.cdll.LoadLibrary(tcmallocdll)
230+
231+
return 'tcmalloc'
232+
233+
return None

webui.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
startup_timer = timer.startup_timer
1111
startup_timer.record("launcher")
1212

13+
malloc = initialize_util.preload_malloc()
14+
if malloc is not None:
15+
startup_timer.record(f"{malloc}")
16+
1317
initialize.imports()
1418

1519
initialize.check_versions()

0 commit comments

Comments
 (0)