File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
src/main/java/com/maxmind/db Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ CHANGELOG
1010 control byte in the data section rather than an
1111 ` ArrayIndexOutOfBoundsException ` . Reported by Edwin Delgado H. GitHub
1212 #68 .
13+ * In order to improve performance when lookups are done from multiple
14+ threads, a use of ` synchronized ` has been removed. GitHub #65 & #69 .
1315
14161.3.1 (2020-03-03)
1517------------------
Original file line number Diff line number Diff line change @@ -58,7 +58,22 @@ final class BufferHolder {
5858 * Returns a duplicate of the underlying ByteBuffer. The returned ByteBuffer
5959 * should not be shared between threads.
6060 */
61- synchronized ByteBuffer get () {
61+ ByteBuffer get () {
62+ // The Java API docs for buffer state:
63+ //
64+ // Buffers are not safe for use by multiple concurrent threads. If a buffer is to be used by more than
65+ // one thread then access to the buffer should be controlled by appropriate synchronization.
66+ //
67+ // As such, you may think that this should be synchronized. This used to be the case, but we had several
68+ // complaints about the synchronization causing contention, e.g.:
69+ //
70+ // * https://github.com/maxmind/MaxMind-DB-Reader-java/issues/65
71+ // * https://github.com/maxmind/MaxMind-DB-Reader-java/pull/69
72+ //
73+ // Given that we are not modifying the original ByteBuffer in any way and all currently known and most
74+ // reasonably imaginable implementations of duplicate() only do read operations on the original buffer object,
75+ // the risk of not synchronizing this call seems relatively low and worth taking for the performance benefit
76+ // when lookups are being done from many threads.
6277 return this .buffer .duplicate ();
6378 }
6479}
You can’t perform that action at this time.
0 commit comments