[JAVA-2230] Create new Document constructor taking initial capacity of LinkedHashMap Created: 17/Jun/16  Updated: 05/Dec/16  Resolved: 05/Dec/16

Status: Closed
Project: Java Driver
Component/s: API, BSON
Affects Version/s: 3.2.2
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: PRAJWAL TULADHAR Assignee: Ross Lawley
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible

 Description   

Currently, when Document class is initialized, it doesn't allow setting `initialCapacity` of internal LinkedHashMap so, that value gets set to 16 everytime. This doesn't work well if I already know number of entries going to be inserted / appended. If number of entries are are less than 16 then, it's kind of creating internal linked list table with bigger size or if entries are greater than 16, it's guaranteed to do `resize()`.

So, it would be nice if Document class exposes new constructor with initial capacity of internal LinkedHashMap.

/**
 * Creates an empty Document instance with custom intial capacity
 */
public Document(int initialCapacity) {
    documentAsMap = new LinkedHashMap<String, Object>(initialCapacity);
}



 Comments   
Comment by Ross Lawley [ 05/Dec/16 ]

Marking as won't fix, as we don't want to expose the current underlying implementation detail of the Document class.

Comment by Ross Lawley [ 08/Jul/16 ]

Apologies for the delay in responding. I recall this coming up at MongoDB World in the JVM birds of a feather.

A reason against adding this constructor is because it exposes internal implementation details of the Document class that could in theory change. Are you facing production issues as a result of not being able to set the initial capacity?

Generated at Thu Feb 08 08:56:40 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.