Skip to content

Commit 73834c9

Browse files
authored
perf: Reduce allocations when writing database (#985)
In my profiling I found 2 things to take the most performance in our application: - the AES encryption - Copies and allocations of Uint8Lists Increasing the size of the initial buffer allocation to one page (4kB) makes those allocations only show up marginally in my profiling. While this is somewhat of a magic number, most systems use a page size of 4kB or larger. While this slightly increases the default memory usage when using hive, I would expect most boxes to have more than 256 bytes of data (which includes key and value). If any application actually uses many boxes of less than 256 bytes, they could probably save more memory by using fewer boxes and at the same time probably improve performance. Signed-off-by: Nicolas Werner <[email protected]>
1 parent 7faa095 commit 73834c9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

hive/lib/src/binary/binary_writer_impl.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'package:meta/meta.dart';
1111

1212
/// Not part of public API
1313
class BinaryWriterImpl extends BinaryWriter {
14-
static const _initBufferSize = 256;
14+
static const _initBufferSize = 4096;
1515

1616
final TypeRegistryImpl _typeRegistry;
1717
Uint8List _buffer = Uint8List(_initBufferSize);

0 commit comments

Comments
 (0)