Port: Optimize tiny_get_max_size inline (e81fe783d)
- Move tiny_get_max_size to header for inlining - Use cached static variable to avoid repeated env lookup - Larson: 51.99M ops/s (stable) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -33,7 +33,26 @@ int hak_is_initializing(void);
|
||||
// HAKMEM_TINY_MAX_CLASS=5 → Tiny handles up to 255B (C0-C5)
|
||||
// HAKMEM_TINY_MAX_CLASS=7 → Tiny handles up to 1023B (C0-C7, default)
|
||||
// Forward declaration (implementation in hakmem_tiny.c)
|
||||
size_t tiny_get_max_size(void);
|
||||
// Optimized: Inline for hot path (0.95% overhead removal)
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
extern bool smallmid_is_enabled(void);
|
||||
|
||||
static inline size_t tiny_get_max_size(void) {
|
||||
static size_t g_cached = 0;
|
||||
if (__builtin_expect(g_cached == 0, 0)) {
|
||||
const char* env = getenv("HAKMEM_TINY_MAX_CLASS");
|
||||
int max_class = 7;
|
||||
if (env && *env) {
|
||||
int parsed = atoi(env);
|
||||
if (parsed >= 0 && parsed < TINY_NUM_CLASSES) max_class = parsed;
|
||||
}
|
||||
if (smallmid_is_enabled() && max_class > 5) max_class = 5;
|
||||
static const size_t sizes[8] = {7, 15, 31, 63, 127, 255, 511, 2047};
|
||||
g_cached = sizes[max_class];
|
||||
}
|
||||
return g_cached;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Phase 3d-B: TLS Cache Merge - Unified TLS SLL Structure
|
||||
|
||||
Reference in New Issue
Block a user