- 
    Type:Task 
- 
    Resolution: Done
- 
    Priority:Major - P3 
- 
    None
- 
    Affects Version/s: None
- 
    Component/s: None
- 
        None
- 
        Not Needed
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
NODE-3976 Description
https://github.com/mongodb/node-mongodb-native/blob/a7a3b99645ec76e4d653537b79263f00b3587e87/src/cursor/abstract_cursor.ts#L630 contains:
const doc = cursor[kDocuments].shift();
In V8, Array.prototype.shift() potentially copies the entirety of the array forward by one element, leading to bad performance for large batch sizes (which we tried using as part of investigating COMPASS-5455 – see attached CPU profile which points to unreasonably much time being spent in nextDocument). Specifically, fetching documents happens in O(nDocuments · batchSize) rather than the expectable O(nDocuments).
If this is adjusted to perform plain array accesses instead of .shift() calls, performance is as expected.
- is depended on by
- 
                    NODE-3976 .shift() usage in nextDocument greatly slows down with large batchSize -         
- Backlog
 
-         
