Skip to content

Commit da08f59

Browse files
committed
optimize: optimized the shdict node struct memory layout which can save 8 bytes for every key-value pair on 64-bit systems, for example.
1 parent 3bd4227 commit da08f59

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/ngx_http_lua_shdict.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,9 @@ ngx_http_lua_shdict_set_helper(lua_State *L, int flags)
11951195
+ key.len
11961196
+ value.len;
11971197

1198+
dd("overhead = %d", (int) (offsetof(ngx_rbtree_node_t, color)
1199+
+ offsetof(ngx_http_lua_shdict_node_t, data)));
1200+
11981201
node = ngx_slab_alloc_locked(ctx->shpool, n);
11991202

12001203
if (node == NULL) {

src/ngx_http_lua_shdict.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313

1414
typedef struct {
1515
u_char color;
16-
u_char dummy;
17-
u_short key_len;
18-
ngx_queue_t queue;
19-
uint64_t expires;
2016
uint8_t value_type;
17+
u_short key_len;
2118
uint32_t value_len;
19+
uint64_t expires;
20+
ngx_queue_t queue;
2221
uint32_t user_flags;
2322
u_char data[1];
2423
} ngx_http_lua_shdict_node_t;

0 commit comments

Comments
 (0)