diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-06-28 14:18:59 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-06-28 14:18:59 -0400 |
| commit | ba7161d6a3156a966c21ea3e06168bdac9803819 (patch) | |
| tree | 0fd65f8513d1ab378be83c79a4ac1db74f38df81 | |
| parent | 8a4d5dc57b14e7c947c25970bb4d4f4ef91450f4 (diff) | |
Greatly increase the maximum free space allocated when growing lists
(from 63 -> 281,474,976,710,655) to fix degenerate performance when
appending to large lists.
| -rw-r--r-- | src/stdlib/datatypes.h | 11 | ||||
| -rw-r--r-- | src/stdlib/paths.c | 2 | ||||
| -rw-r--r-- | src/stdlib/text.c | 2 |
3 files changed, 8 insertions, 7 deletions
diff --git a/src/stdlib/datatypes.h b/src/stdlib/datatypes.h index 77c09ddb..135fb811 100644 --- a/src/stdlib/datatypes.h +++ b/src/stdlib/datatypes.h @@ -7,12 +7,13 @@ #include <stdint.h> #include <time.h> -#define LIST_LENGTH_BITS 42 -#define LIST_FREE_BITS 6 +#define LIST_LENGTH_BITS 64 +#define LIST_FREE_BITS 48 +#define LIST_ATOMIC_BITS 1 #define LIST_REFCOUNT_BITS 3 #define LIST_STRIDE_BITS 12 -#define MAX_FOR_N_BITS(N) ((1<<(N))-1) +#define MAX_FOR_N_BITS(N) ((1L<<(N))-1L) #define LIST_MAX_STRIDE MAX_FOR_N_BITS(LIST_STRIDE_BITS-1) #define LIST_MIN_STRIDE (~MAX_FOR_N_BITS(LIST_STRIDE_BITS-1)) #define LIST_MAX_DATA_REFCOUNT MAX_FOR_N_BITS(LIST_REFCOUNT_BITS) @@ -42,8 +43,8 @@ typedef struct { // bit arithmetic to extract the necessary values, which is cheaper than // spilling onto the stack and needing to retrieve data from the stack. int64_t length:LIST_LENGTH_BITS; - uint8_t free:LIST_FREE_BITS; - bool atomic:1; + uint64_t free:LIST_FREE_BITS; + bool atomic:LIST_ATOMIC_BITS; uint8_t data_refcount:LIST_REFCOUNT_BITS; int16_t stride:LIST_STRIDE_BITS; } List_t; diff --git a/src/stdlib/paths.c b/src/stdlib/paths.c index 772fa1fd..94baf995 100644 --- a/src/stdlib/paths.c +++ b/src/stdlib/paths.c @@ -372,7 +372,7 @@ public OptionalList_t Path$read_bytes(Path_t path, OptionalInt_t count) close(fd); if (count.small != 0 && (int64_t)len < target_count) fail("Could not read ", target_count, " bytes from ", path, " (only got ", (uint64_t)len, ")"); - return (List_t){.data=content, .atomic=1, .stride=1, .length=len}; + return (List_t){.data=content, .atomic=1, .stride=1, .length=(int64_t)len}; } } diff --git a/src/stdlib/text.c b/src/stdlib/text.c index 9dedccdd..0f3f9519 100644 --- a/src/stdlib/text.c +++ b/src/stdlib/text.c @@ -1477,7 +1477,7 @@ public List_t Text$utf32_codepoints(Text_t text) public List_t Text$utf8_bytes(Text_t text) { const char *str = Text$as_c_string(text); - return (List_t){.length=strlen(str), .stride=1, .atomic=1, .data=(void*)str}; + return (List_t){.length=(int64_t)strlen(str), .stride=1, .atomic=1, .data=(void*)str}; } static INLINE const char *codepoint_name(ucs4_t c) |
