From a90c85023c7c57bda71811ba00e65b43617939d8 Mon Sep 17 00:00:00 2001 From: Philip Monk Date: Mon, 28 Nov 2022 16:49:07 -0700 Subject: [PATCH] u3: add comment explaining willoc logic --- pkg/urbit/noun/allocate.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/urbit/noun/allocate.c b/pkg/urbit/noun/allocate.c index f7ce67958..4667b7ba8 100644 --- a/pkg/urbit/noun/allocate.c +++ b/pkg/urbit/noun/allocate.c @@ -425,8 +425,18 @@ _ca_willoc(c3_w len_w, c3_w ald_w, c3_w alp_w) alp_w = (alp_w + c3_wiseof(u3a_box)) % ald_w; - // XX: this logic is totally bizarre, but preserve it. - // + /* XX: this logic is totally bizarre, but preserve it. + ** + ** This means we use the next size bigger instead of the "correct" + ** size. For example, a 20 word allocation will be freed into free + ** list 2 but will be allocated from free list 3. + ** + ** This is important to preserve because the sequential search may be + ** very slow. On a real-world task involving many compilations, + ** removing this line made this function appear in ~80% of samples. + ** + ** For reference, this was added in cgyarvin/urbit ffed9e748d8f6c. + */ if ( (sel_w != 0) && (sel_w != u3a_fbox_no - 1) ) { sel_w += 1; }