[libc-commits] [libc] [libc] Use best-fit binary trie to make malloc logarithmic (PR #106259)

via libc-commits libc-commits at lists.llvm.org
Thu Oct 10 10:41:13 PDT 2024


================
@@ -0,0 +1,252 @@
+//===-- Interface for freetrie --------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_FREETRIE_H
+#define LLVM_LIBC_SRC___SUPPORT_FREETRIE_H
+
+#include "freelist.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+/// A trie of free lists.
+
+class FreeTrie {
----------------
nopsledder wrote:

I think a comment is needed to describe the basic operation the trie. I fell into the trap of assume the nodes were between the left and right children, like a binary tree. It took me some careful reading to realize that the children are both half ranges and the mode is merely _somewhere_ in the range.

I think it would be useful to call out the reason for this (fast replacement of the root), and the fact that this is logarithmic in terms of _the addressable size_ and not in terms of the number of nodes in the tree. 

https://github.com/llvm/llvm-project/pull/106259


More information about the libc-commits mailing list