symbol.c: implement adaptive symbol table for memory efficiency

Replace fixed 256-element hash array in mrb_state with adaptive approach:
- Linear search for <=255 symbols (typical embedded use case)
- Hash table allocated on-demand when symbols exceed threshold
- Reduces mrb_state size by 1KB per instance (1068->36 bytes in symbol fields)
- Configurable threshold via MRB_SYMBOL_LINEAR_THRESHOLD in mrbconf.h

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2025-08-08 01:10:04 +09:00
parent 3494b699ef
commit a217935e7d
3 changed files with 225 additions and 41 deletions
+2 -3
View File
@@ -155,6 +155,7 @@ typedef uint8_t mrb_code;
typedef uint32_t mrb_aspec;
typedef struct mrb_irep mrb_irep;
struct mrb_state;
#ifndef MRB_FIXED_STATE_ATEXIT_STACK_SIZE
@@ -281,10 +282,8 @@ typedef struct mrb_state {
mrb_sym symidx;
const char **symtbl;
uint8_t *symlink;
uint8_t *symflags;
mrb_sym symhash[256];
size_t symcapa;
struct mrb_sym_hash_table *symhash;
#ifndef MRB_USE_ALL_SYMBOLS
char symbuf[8]; /* buffer for small symbol names */
#endif