diff --git a/src/lsm/groove.zig b/src/lsm/groove.zig index 855ca4f59f..59dc602209 100644 --- a/src/lsm/groove.zig +++ b/src/lsm/groove.zig @@ -471,8 +471,10 @@ pub fn GrooveType( scan_builder: ScanBuilder, pub const Options = struct { - /// The maximum number of objects that might be prefetched by a batch. - prefetch_entries_max: u32, + /// The maximum number of objects that might be prefetched and not modified by a batch. + prefetch_entries_for_read_max: u32, + /// The maximum number of objects that might be prefetched and then modified by a batch. + prefetch_entries_for_update_max: u32, cache_entries_max: u32, tree_options_object: ObjectTree.Options, @@ -491,9 +493,10 @@ pub fn GrooveType( // In the worst case, each Map must be able to store the value_count_max (to // contain either TableMutable or TableImmutable) as well as the maximum number of - // prefetches a bar may perform. + // prefetches a bar may perform, excluding prefetches already accounted for by + // value_count_max. .map_value_count_max = @as(u32, ObjectTree.Table.value_count_max) + - (options.prefetch_entries_max * constants.lsm_batch_multiple), + (options.prefetch_entries_for_read_max * constants.lsm_batch_multiple), // Scopes are limited to a single beat, so the maximum number of entries in a // single scope is value_count_max / constants.lsm_batch_multiple. @@ -554,7 +557,10 @@ pub fn GrooveType( } var prefetch_keys = PrefetchKeys{}; - try prefetch_keys.ensureTotalCapacity(allocator, options.prefetch_entries_max); + try prefetch_keys.ensureTotalCapacity( + allocator, + options.prefetch_entries_for_read_max + options.prefetch_entries_for_update_max, + ); errdefer prefetch_keys.deinit(allocator); var scan_builder = if (has_scan) try ScanBuilder.init(allocator) else {}; diff --git a/src/state_machine.zig b/src/state_machine.zig index 0ff5820c80..cc0b64f776 100644 --- a/src/state_machine.zig +++ b/src/state_machine.zig @@ -1315,12 +1315,11 @@ pub fn StateMachineType( return .{ .accounts = .{ - .prefetch_entries_max = @max( - // create_account()/lookup_account() looks up 1 AccountImmutable per item. - batch_accounts_max, - // create_transfer()/post_or_void_pending_transfer() looks up 2 - // AccountImmutables for every transfer. - 2 * batch_transfers_max, + // lookup_account() looks up 1 AccountImmutable per item. + .prefetch_entries_for_read_max = batch_accounts_max, + .prefetch_entries_for_update_max = @max( + batch_accounts_max, // create_account() + 2 * batch_transfers_max, // create_transfer(), debit and credit accounts ), .cache_entries_max = options.cache_entries_accounts, .tree_options_object = .{}, @@ -1338,8 +1337,11 @@ pub fn StateMachineType( }, }, .transfers = .{ - // *2 to fetch pending and post/void transfer. - .prefetch_entries_max = 2 * batch_transfers_max, + // lookup_transfer() looks up 1 Transfer. + // create_transfer() looks up at most 1 Transfer for posting/voiding. + .prefetch_entries_for_read_max = batch_transfers_max, + // create_transfer() updates a single Transfer. + .prefetch_entries_for_update_max = batch_transfers_max, .cache_entries_max = options.cache_entries_transfers, .tree_options_object = .{}, .tree_options_id = .{}, @@ -1357,7 +1359,10 @@ pub fn StateMachineType( }, }, .posted = .{ - .prefetch_entries_max = batch_transfers_max, + // Nothing lookups posted groove. + .prefetch_entries_for_read_max = 0, + // create_transfer() posts/voids at most one transfer. + .prefetch_entries_for_update_max = batch_transfers_max, .cache_entries_max = options.cache_entries_posted, .tree_options_object = .{}, .tree_options_id = {}, diff --git a/src/testing/state_machine.zig b/src/testing/state_machine.zig index 684c7378e1..3d1c5ae771 100644 --- a/src/testing/state_machine.zig +++ b/src/testing/state_machine.zig @@ -108,7 +108,8 @@ pub fn StateMachineType( .{ .things = .{ .cache_entries_max = 2048, - .prefetch_entries_max = 1, + .prefetch_entries_for_read_max = 0, + .prefetch_entries_for_update_max = 1, .tree_options_object = .{}, .tree_options_id = .{}, .tree_options_index = .{ .value = .{} },