[JAVA-4816] Improve performance of ObjectId hex string parsing Created: 22/Nov/22 Updated: 28/Oct/23 Resolved: 13/Dec/22 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | BSON |
| Affects Version/s: | None |
| Fix Version/s: | 4.9.0 |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Ian White | Assignee: | Jeffrey Yemin |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Fully Compatible |
| Documentation Changes: | Not Needed |
| Description |
|
The built-in ObjectId parseHexString() implementation is somewhat slow, because it calls Integer.parseInt() 12 times. Replacing with hand-coded hex parsing achieves something like a 5x improvement. Performance test (ran on master and on branch on my M1 Mac): public static void main(String[] args) { long endTime = System.currentTimeMillis(); System.out.println("Time elapsed: " + (endTime - startTime)); On master: Time elapsed: 19460 On branch: Time elapsed: 3617 |
| Comments |
| Comment by Githook User [ 13/Dec/22 ] |
|
Author: {'name': 'Ian White', 'email': 'ian@charthop.com', 'username': 'eonwhite'}Message: Improve performance of ObjectId#parseHexString (#1034) Co-authored-by: Jeff Yemin <jeff.yemin@mongodb.com> |