Skip to content

Commit 549ed2a

Browse files
committed
restore: optimize funk_rec allocs
1 parent 0a7bad9 commit 549ed2a

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/discof/restore/fd_snapin_tile_funk.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,31 @@
33
#include "fd_snapin_tile_private.h"
44
#include "../../flamenco/accdb/fd_accdb_sync.h"
55

6+
/* rec_pool_acquire is a fast lock-free version of
7+
fd_funk_rec_pool_acquire. Does bump allocation only. */
8+
9+
static inline fd_funk_rec_t *
10+
rec_pool_acquire( fd_funk_rec_pool_t * join ) {
11+
fd_funk_rec_t * ele0 = join->ele;
12+
ulong ele_max = join->ele_max;
13+
14+
ulong ver_lazy = join->pool->ver_lazy;
15+
16+
ulong ver = fd_funk_rec_pool_private_vidx_ver( ver_lazy );
17+
ulong ele_idx = fd_funk_rec_pool_private_vidx_idx( ver_lazy );
18+
19+
if( FD_UNLIKELY( fd_funk_rec_pool_idx_is_null( ele_idx ) ) ) {
20+
return NULL;
21+
}
22+
23+
ulong ele_nxt = ele_idx+1UL;
24+
if( FD_UNLIKELY( ele_nxt>=ele_max ) ) ele_nxt = fd_funk_rec_pool_idx_null();
25+
26+
ulong new_ver_lazy = fd_funk_rec_pool_private_vidx( ver, ele_nxt );
27+
join->pool->ver_lazy = new_ver_lazy;
28+
return ele0 + ele_idx;
29+
}
30+
631
int
732
fd_snapin_process_account_header_funk( fd_snapin_tile_t * ctx,
833
fd_ssparse_advance_result_t * result ) {
@@ -189,7 +214,7 @@ fd_snapin_process_account_batch_funk( fd_snapin_tile_t * ctx,
189214

190215
fd_funk_rec_t * r = rec[ i ];
191216
if( FD_LIKELY( !r ) ) { /* optimize for new account */
192-
r = fd_funk_rec_pool_acquire( funk->rec_pool, NULL, 0, NULL );
217+
r = rec_pool_acquire( funk->rec_pool );
193218
FD_TEST( r );
194219
memset( r, 0, sizeof(fd_funk_rec_t) );
195220
fd_funk_txn_xid_copy( r->pair.xid, ctx->xid );

0 commit comments

Comments
 (0)