Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
From the author of

NonSerialized()

There's another thing—which isn't first and foremost a performance optimization—that can help when it comes to reducing serialization size: to mark context-aware fields with <NonSerialized()>. For EntityBase, an example is the expander instance, which helps to expand a collapsed instance, implicitly or explicitly. I don't want that instance to travel over the network anyway, so it's just fine to mark it as <NonSerialized()>.

Another trick is to cache values in EntityBase that are marked as <NonSerialized()> (an example is the offsets I need to use for navigating in the object vector). Those values can be found by asking the subclasses, but because the EntityBase needs them very frequently, I cache them in the EntityBase and I only access them in EntityBase via private read-only properties. Once again, the fields in EntityBase are not serialized to save on serialization space. This is a tweak that probably can be used for many situations.

  • + Share This
  • 🔖 Save To Your Account