Skip to content

Commit ab6a6a0

Browse files
committed
Resolve write performance regression (fixes #268)
Bisection using the LmdbJava Benchmarks project identified a 40% write performance regression introduced in commit 68f0a44: Commit Date Score Change Message =============================================================================== be2a15b 2023-02-04 00:28:16 89.07 [maven-release-plugin] pr 1cc7e6c 2023-12-04 07:42:08 94.49 +6.09% Test on Java 21 f17b63f 2023-12-05 01:34:17 91.57 -3.09% [maven-release-plugin] pr b5dfb25 2025-02-16 23:37:16 91.38 -0.21% Uplift lmdb from 0.9.29 t * 68f0a44 2025-02-16 23:46:30 128.63 +40.76% Add DbiFlags#MDB_UNSIGNED 928cf7b 2025-02-20 01:26:13 129.12 +0.38% Add url element to pom.xm dc24f4b 2025-10-31 00:20:59 122.03 -5.49% Generalise benchmark link Root cause: MaskedFlag.mask() was changed from a simple for-loop to Stream API in commit 68f0a44. This method is invoked once per write operation (Cursor.put() line 255), causing significant overhead from stream creation, lambda allocation, and boxing/unboxing. Fix: Restore for-loop implementation while preserving the onlyPropagatedToLmdb filtering logic added in 68f0a44. Performance verified with 1M entry write benchmark: - Before fix: 122.03 ms/op - After fix: 90.43 ms/op (within 2% of baseline 89.07 ms/op)
1 parent dc24f4b commit ab6a6a0

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/main/java/org/lmdbjava/MaskedFlag.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,20 @@ static <M extends MaskedFlag> int mask(final Stream<M> flags) {
7575
*/
7676
@SafeVarargs
7777
static <M extends MaskedFlag> int mask(final boolean onlyPropagatedToLmdb, final M... flags) {
78-
return flags == null ? 0 : mask(onlyPropagatedToLmdb, Arrays.stream(flags));
78+
if (flags == null || flags.length == 0) {
79+
return 0;
80+
}
81+
82+
int result = 0;
83+
for (final M flag : flags) {
84+
if (flag == null) {
85+
continue;
86+
}
87+
if (!onlyPropagatedToLmdb || flag.isPropagatedToLmdb()) {
88+
result |= flag.getMask();
89+
}
90+
}
91+
return result;
7992
}
8093

8194
/**

0 commit comments

Comments
 (0)