Commit Graph

6 Commits

Author SHA1 Message Date
Andreas Kling
b23aa38546 AK: Adopt mimalloc v2 as main allocator
Use mimalloc for Ladybird-owned allocations without overriding malloc().
Route kmalloc(), kcalloc(), krealloc(), and kfree() through mimalloc,
and put the embedded Rust crates on the same allocator via a shared
shim in AK/kmalloc.cpp.

This also lets us drop kfree_sized(), since it no longer used its size
argument. StringData, Utf16StringData, JS object storage, Rust error
strings, and the CoreAudio playback helpers can all free their AK-backed
storage with plain kfree().

Sanitizer builds still use the system allocator. LeakSanitizer does not
reliably trace references stored in mimalloc-managed AK containers, so
static caches and other long-lived roots can look leaked. Pass the old
size into the Rust realloc shim so aligned fallback reallocations can
move posix_memalign-backed blocks safely.

Static builds still need a little linker help. macOS app binaries need
the Rust allocator entry points forced in from liblagom-ak.a, while
static ELF links can pull in identical allocator shim definitions from
multiple Rust staticlibs. Keep the Apple -u flags and allow those
duplicate shim symbols for LibJS and LibRegex links on Linux and BSD.
2026-04-08 09:57:53 +02:00
Ben Wiederhake
b13df3a426 AK: Remove unused include from ByteStringImpl 2026-02-17 12:38:51 +00:00
Andreas Kling
ce44ca57ea AK: Use constinit for the empty ByteStringImpl
Replace the lazy heap allocation with a constinit static that is
initialized at compile time. This eliminates both the heap allocation
and the runtime guard variable check on every access.

The EmptyByteStringImpl struct mirrors the exact layout of
ByteStringImpl and is verified with static_asserts.
2026-01-25 09:32:51 +01:00
Zaggy1024
2e44bc1576 AK: Make ByteStringImpl atomically ref-counted
We reference the empty string across multiple threads, and without
counting references atomically, we may end up freeing the empty string.

This is required by demuxers in LibMedia. Threading::Thread also
defaults to the empty string when no thread name is provided, so a
thread cannot be created off the main thread safely without this
change.

js-benchmarks and web-benchmarks both show minimal differences in
performance.
2026-01-23 09:20:15 +01:00
Ali Mohammad Pur
4462348916 Everywhere: Slap some [[clang::lifetimebound]] where appropriate
This first pass only applies to the following two cases:
- Public functions returning a view type into an object they own
- Public ctors storing a view type

This catches a grand total of one (1) issue, which is fixed in
the previous commit.
2025-09-01 11:11:38 +02:00
Timothy Flynn
3f439efe21 AK: Rename StringImpl to ByteStringImpl
StringImpl is very specific to ByteString. Let's rename it to match, to
avoid confusion with the StringBase and StringData classes.
2025-04-07 17:44:38 +02:00