[CSHARP-105] Driver shouldn't try to find discriminator when deserializing if the nominalType is sealed or ClassMap.DiscriminatorIsRequired is false Created: 19/Nov/10  Updated: 02/Apr/15  Resolved: 07/Apr/11

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 0.9
Fix Version/s: 1.1

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


 Description   

Driver shouldn't try to find discriminator when deserializing if the nominalType is sealed or ClassMap.DiscriminatorIsRequired is false. Currently it always tries to look up for discriminator even though it's not necessary



 Comments   
Comment by Robert Stam [ 07/Apr/11 ]

I ended up implementing this optimization in a slightly different way: the driver keeps track of which classes have discriminators registered for them. That way it can figure out automatically whether it is safe to skip looking for a discriminator or not based on the nominalType of the class being deserialized (because if no subclass of nominalType has a discriminator registered there's no need to look for one).

Comment by Testo [ 22/Nov/10 ]

then there should either
1. have a configurable way to do so via BsonClassMap
2. add additional custom attribute to configure this
3. add convention setting to say that for my object models, I don't have discriminator

Comment by Robert Stam [ 22/Nov/10 ]

I agree. We need to be careful about knowing when it is safe to skip looking for a discriminator. DiscriminatorIsRequired false doesn't necessarily mean there is no discriminator. My thinking is that we can skip looking for a discriminator when the nominalType has no subclasses (sealed guarantees that, but even non-sealed classes often don't have subclasses). This is on my TODO list.

Comment by Testo [ 22/Nov/10 ]

this can help read performance significantly as it doesn't need to go through elements twice for most of the classes without discriminator

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