[CSHARP-1067] ObjectId could have a slightly smaller internal representation Created: 16/Sep/14  Updated: 20/Jan/16  Resolved: 10/Aug/15

Status: Closed
Project: C# Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: 2.1

Type: Improvement Priority: Major - P3
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

An ObjectId is 12 bytes long, but our current implementation:

private int _timestamp;
private int _machine;
private short _pid;
private int _increment;

means that 14 bytes are used. (two fields, _machine and _increment, are 1 byte larger than they need to be).

We could instead represent the 12 bytes internally as:

private int _a;
private int _b;
private int _c;

Which is exactly 12 bytes.

We could easily reimplement the Timestamp, MachineId, Pid and Increment properties to extract the necessary bytes from _a, _b and _c and synthesize the corresponding return value, so this would not be a backward breaking change.



 Comments   
Comment by Githook User [ 10/Aug/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1067: Added FromByteArray helper method.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/a9be63b3433fae698b966a22c582c74618977161

Comment by Githook User [ 10/Aug/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1067: Code review changes.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/fd39739389f6fc9101ac811127dd951c7593c82e

Comment by Githook User [ 10/Aug/15 ]

Author:

{u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}

Message: CSHARP-1067: Use slightly smaller internal representation for ObjectId.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/89944e07d11ad360680d7aa7065d7828a07f9af6

Generated at Wed Feb 07 21:38:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.