Skip to content

Commit

Permalink
perf: Reduce allocations when writing database (isar#985)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
nico-famedly authored May 31, 2022
1 parent 7faa095 commit 73834c9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion hive/lib/src/binary/binary_writer_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:meta/meta.dart';

/// Not part of public API
class BinaryWriterImpl extends BinaryWriter {
static const _initBufferSize = 256;
static const _initBufferSize = 4096;

final TypeRegistryImpl _typeRegistry;
Uint8List _buffer = Uint8List(_initBufferSize);
Expand Down

0 comments on commit 73834c9

Please sign in to comment.