title: MapDB fixed structure of key and value
body: <p>I would like to store a couple billion key,value pairs in MapDB.  I have specific requirements:</p>
  
  <p>key = long (8 bytes)
  value = maximum 5 entries of (UUID + from-date + to-date), so 5 * 32 bytes = 160</p>
  
  <p>Requirement is to have single threaded app: load by key, and change one of the dates in the entries.  The size of the value will not change.</p>
  
  <p>I wonder what the most efficient setup is to do gets and puts.  Do I gain performance by pre-allocating a byte array of 160 and use that as the value?  Or doesn't it matter and just use a byte array flexible in size?</p>
  
  <p>Currently I have </p>
  
  <pre><code>       DB db = DBMaker
              .newFileDB(dbFile)
              .asyncWriteEnable()
              .asyncWriteFlushDelay(100)
              .transactionDisable()
              .make();
  </code></pre>
  
  <p>Pump:</p>
  
  <pre><code>       BTreeKeySerializer keySerializer = BTreeKeySerializer.ZERO_OR_POSITIVE_LONG;
         Map&lt;Long, Item&gt; map = db.createTreeMap("map")
              .pumpSource(source)
              .keySerializer(keySerializer)
              .make();
  </code></pre>
  
  <p>where source is</p>
  
  <pre><code>Iterator&lt;Fun.Tuple2&lt;Long, byte[]&gt;&gt; source = new Iterator&lt;Fun.Tuple2&lt;Long, byte[]&gt;&gt;()
  </code></pre>
  
  <p>Loading</p>
  
  <pre><code>        Map&lt;Long, byte[]&gt; map = db.&lt;Long, byte[]&gt;getTreeMap("map");
  </code></pre>
  
  <p>After using the datapump to load the map with 20,000,000 items (performance degrades over time), the lookups are a bit disappointing:</p>
  
  <p>200,000 lookups in 199,999 ms.  (about 1000 / second)</p>
  
  <p>the lookup increases dramatically after running my test app a second time:</p>
  
  <p>200,000 lookups in 7,597 ms.</p>
  
  <p>Is there anything I can do to improve the performance given the fixed size requirements of the keys/values?   Any options I can enable?</p>
  
  <p>I used a TreeMap because it has a data pump.  Would performance increase significantly when using a HashMap?</p>
  
  <p>Cheers! </p>