Repository navigation
BSOA Caveats
BSOA object models look very similar to normal object models, but behave differently in a few keys ways.
- Use the constructors which take a root object.
- Fully initialize all properties before adding the object to a collection or setting a reference to it.
- Convert DateTimes to UTC before setting.
- Cache returned objects (strings, Lists) to avoid retrieving them repeatedly.
- Keep Dictionaries small if possible.
- Enumerate collections with foreach() for best performance.
All BSOA objects must be tied to a Table which holds the data. Constructors which take the root object will create it in the correct table. Other constructors will guess, putting the object under the last created root for the current thread.
When objects from one root are set on the object model of another, they are copied. This takes time, and means that changes to the object after it is set will not apply to both copies.
BSOA object models copy values into internal data structures on set. This means that if you make changes to a value after setting it, the changes will not take effect on the copy in BSOA. For example, if you set a BSOA object property to a List and then add more strings to it, the strings added after you set the list will not be on the BSOA copy.
All DateTimes in BSOA are stored as UTC. If you set a DateTime BSOA property and read it back, the value returned will have been converted to a Universal time.
Strings inside BSOA are stored as UTF-8 bytes, and must be converted to .NET strings when they are retrieved. Keep a copy of the string in a variable to avoid repeated string conversions when you're referencing the string multiple times. BSOA caches the last string retrieved from each column to make multiple accesses of the same single value lower cost.
BSOA Dictionaries for a given object model property are all stored together. Each Dictionary's keys are stored in sorted order, but this isn't as fast as the hash lookup that "stored separately" Dictionaries can use. String keys may have to be converted from UTF-8 during many operations. BSOA is optimized so that Dictionaries with fewer than 256 distinct keys keep them cached as strings internally.
In BSOA, enumerating with foreach is fastest. The semantics of foreach allow BSOA to get a snapshot of the items in a collection once and then iterate over it. Checking the Count of a collection or accessing the item at an index must re-check the collection to see if the items within have changed, since the list objects you work with don't "own" the collection data itself.
All BSOA objects which are created will end up in the Table. If you create an object instance but never put it into a collection reachable from the root object, BSOA must garbage collect it. If you are creating many objects but will only keep some of them, it's best to create a "scratch" root object. When you add instances to collections in your "real" object, BSOA will copy the data to the tables to be output.
In addition, BSOA objects are not garbage collected normally during execution. Any instances kept in memory will hold the root object and all other objects created in the table. If you want to create objects as you go without keeping them all in memory, you need to avoid keeping instances. If you're serializing them periodically, you should call root.DB.Clear() after each serialization to get rid of previously added data.