[CSHARP-1064] Have pre-created BsonValue instances for common values Created: 16/Sep/14 Updated: 20/Jan/16 Resolved: 26/May/15 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | BSON |
| Affects Version/s: | None |
| Fix Version/s: | 2.1 |
| Type: | Improvement | Priority: | Minor - P4 |
| 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 |
|
We could reduce pressure on the GC by having pre-created instances of many commonly used BsonValues. For example: BsonBoolean: true, false The way these would be taken advantage of would be in the implicit conversions from primitive types to BsonValues. For example:
|
| Comments |
| Comment by Githook User [ 26/May/15 ] |
|
Author: {u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}Message: |
| Comment by Githook User [ 26/May/15 ] |
|
Author: {u'username': u'rstam', u'name': u'rstam', u'email': u'robert@robertstam.org'}Message: |
| Comment by Roman Kuzmin [ 17/Sep/14 ] |
|
I do not think it is harmful but I do not expect significant improvements either. It is difficult to tell without benchmarks. And proper benchmarks which reflect practical use cases are not that easy. |
| Comment by Robert Stam [ 17/Sep/14 ] |
|
The idea with numbers is that certain constants appear frequently. Particularly 0 and 1 (0.0 and 1.0 for doubles). But it is quite cheap to extend the concept to a few hundred values (e.g. -100 to 100) as long as they are consecutive, so we don't have to do a dictionary lookup. Why do you say this approach is not necessarily more effective? Do you think it would be harmful in any way? |
| Comment by Roman Kuzmin [ 17/Sep/14 ] |
|
It looks reasonable perhaps for bool and an empty string but for numbers it is rather odd, especially for double. And this approach is not necessarily more effective. |