Skip to content

[mimalloc] Disable profiling and nonessential stats - #28084

Merged
sbc100 merged 1 commit into
emscripten-core:mainfrom
kleisauke:mimalloc-opt-size
Oct 27, 2026
Merged

sbc100 merged 1 commit into
emscripten-core:mainfrom
kleisauke:mimalloc-opt-size

Conversation

@kleisauke

Copy link
Copy Markdown
Collaborator

Set MI_PROFILE=0 and MI_STATS=0 to reduce code size by disabling
profiling and nonessential statistics.

Define MI_NO_GETENV in preparation for upstream mimalloc support,
as Emscripten already does not support environment customization.

Set `MI_PROFILE=0` and `MI_STATS=0` to reduce code size by disabling
profiling and nonessential statistics.

Define `MI_NO_GETENV` in preparation for upstream mimalloc support,
as Emscripten already does not support environment customization.
@kleisauke

Copy link
Copy Markdown
Collaborator Author
  • -DMI_NO_GETENV is NFC, as we already don't support environ customization:
    int _mi_prim_getenv(const char* name, char* result, size_t result_size) {
    // For code size reasons, do not support environ customization for now.
    MI_UNUSED(name);
    MI_UNUSED(result);
    MI_UNUSED(result_size);
    return 0; // not found
    }

    it's being added in preparation for commit microsoft/mimalloc@0fec3da, which introduces support for it.
  • -DMI_PROFILE=0 -DMI_STATS=0 is not NFC, see:
    // Statistics (0=only essential, 1=detailed (fast, can be enabled always), 2=slightly more expensive tracking of precise requested bytes)
    #ifndef MI_STATS
    #if (MI_DEBUG>0)
    #define MI_STATS 2
    #else
    #define MI_STATS 1
    #endif
    #endif
    // Enable profiling support (0=off, 1=fast, can be enabled always, 2=allow fine-grained sample rates(<64 KiB), a tad more expensive)
    #ifndef MI_PROFILE
    #define MI_PROFILE 1
    #endif

    but helps to reduce the code size (see the updated codesize expectations for both other.test_malloc_size_mimalloc and other.test_malloc_size_mimalloc_O2).

Tested with:

$ ./test/runner {core2,wasmfs,wasm64_4gb}.test_wrap_malloc_mimalloc other.test_malloc_size_mimalloc* other.test_malloc_multithreading_mimalloc* other.test_mimalloc_options
Running 8 tests
Using 8 parallel test processes
[8/8] test_malloc_size_mimalloc_O2 (test_other.other.test_malloc_size_mimalloc_O2) ... ok

----------------------------------------------------------------------
Ran 8 tests in 1.157s

OK
Total core time: 3.791s. Wallclock time: 1.157s. Parallelization: 3.28x.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request reduces the code size of the mimalloc library by disabling environment customization, profiling, and nonessential statistics via compiler flags (-DMI_NO_GETENV, -DMI_PROFILE=0, and -DMI_STATS=0). Consequently, the expected code sizes in test_other.py and the expected output in test_mimalloc_options.out have been updated to reflect these changes. There are no review comments, so no feedback is provided.

@sbc100
sbc100 merged commit 260bae3 into emscripten-core:main Oct 27, 2026
42 checks passed
@kleisauke
kleisauke deleted the mimalloc-opt-size branch October 27, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants