Skip to content

Commit

Permalink
fix(accounts-db): reduce bufferpool reads (#602)
Browse files Browse the repository at this point in the history
replaces two bufferpool reads in `getAccountHashAndLamports` with a
single call
  • Loading branch information
0xNineteen authored Mar 6, 2025
1 parent c8fc2bf commit e04ab97
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/accountsdb/accounts_file.zig
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ pub const AccountFile = struct {
return number_of_accounts;
}

/// get account without reading data (a lot faster if the data field isnt used anyway)
/// get account without reading the data field (a lot faster)
/// (used when computing account hashes for snapshot validation)
pub fn getAccountHashAndLamports(
self: *const Self,
Expand All @@ -336,12 +336,31 @@ pub const AccountFile = struct {
offset += @sizeOf(AccountInFile.StorageInfo);
offset = std.mem.alignForward(usize, offset, @sizeOf(u64));

const lamports = try self.getType(metadata_allocator, buffer_pool, &offset, u64);
const buf_size = @sizeOf(AccountInFile.AccountInfo) + @sizeOf(Hash);

offset += @sizeOf(AccountInFile.AccountInfo) - @sizeOf(u64);
offset = std.mem.alignForward(usize, offset, @sizeOf(u64));
const read = try self.getSlice(
metadata_allocator,
buffer_pool,
&offset,
buf_size,
);
defer read.deinit(metadata_allocator);

var buf: [buf_size]u8 = undefined;
read.readAll(&buf);

var account_info: AccountInFile.AccountInfo = undefined;
@memcpy(
std.mem.asBytes(&account_info),
buf[0..][0..@sizeOf(AccountInFile.AccountInfo)],
);
const lamports = account_info.lamports;

const hash = try self.getType(metadata_allocator, buffer_pool, &offset, Hash);
var hash: Hash = undefined;
@memcpy(
std.mem.asBytes(&hash),
buf[@sizeOf(AccountInFile.AccountInfo)..][0..@sizeOf(Hash)],
);

return .{
.hash = hash,
Expand Down

0 comments on commit e04ab97

Please sign in to comment.