[SERVER-2098] BSONArrayBuilder::subXStart, various forms of inefficiency Created: 16/Nov/10 Updated: 12/Jul/16 Resolved: 31/Mar/11 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Internal Client |
| Affects Version/s: | 1.6.2, 1.6.3, 1.6.4, 1.7.0, 1.7.1, 1.7.2 |
| Fix Version/s: | 1.9.0 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Andrew Morrow (Inactive) | Assignee: | Mathias Stearn |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
BSONArrayBuilder has a few rather serious performance glitches around subarrayStart and subobjStart, specifically: These functions require that you provide a 'name' for the element that you wish to start, as a string. As a result, you are forced into a strlen call (to populate StringData) and a strtol call (to convert the string to an integer), and to keep your own external integer counter to convert to a string. This is mostly useless: the common use case here is just to start the next element in the series, and BSONArrayBuilder already keeps an internal counter. I think you could just have: subarrayStart(); // auto-increment to next index This would let most users never have to worry about this stuff at all (since they are starting array elements in order), let more advanced users use a more efficient mechanism that avoids string processing when using offsets by providing integer offsets, and finally provide a way forward for the more general case. Finally, what should the behavior be if you specifiy a 'name' (index) for an element and you are already beyond that many elements in the array? It appears that the provided name'is just ignored in this case. Perhaps that should be an error? |
| Comments |
| Comment by Andrew Morrow (Inactive) [ 01/Apr/11 ] |
|
Hey Mathias - That looks great. It might be a few weeks until I can get around to building Andrew |
| Comment by Mathias Stearn [ 31/Mar/11 ] |
|
For now I left it ignoring numbers less than next, but at least it is doc'd now. |
| Comment by auto [ 31/Mar/11 ] |
|
Author: {u'login': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}Message: Better BSONArrayBuilder::sub {obj,array}Start |