8000 Reduce the Specification size. Set the initial state to null. · Issue #415 · ardalis/Specification · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Reduce the Specification size. Set the initial state to null. #415
Closed
@fiseni

Description

@fiseni

The specification state is not optimized at all and we have a lot of unnecessary memory allocations. This is partly because many users have assumptions about the internals and we have avoided breaking user code (even though technically it's not a breaking change). But, it's time to change that. For the upcoming version 9, we'll be not so aggressive, and we won't refactor everything from the ground up. We'll try to keep the public API mostly the same, but it will be a breaking change for the folks who've been relying on the internals.

The specification state mostly consists of various expression collections. Currently, all these collections are initialized during instantiation. So, we have several list objects regardless if they're used by the spec or not. This is wasteful, a single empty list allocates 56 bytes of memory.

In version 9 we'll set all the initial states to null. We'll still be spending 8 bytes per reference (on x64), it's not ideal and we have further plans for version 10. But, taking this incremental step would reduce the size of specifications considerably. The aim is to keep the size ~100 bytes for empty specs (currently is over 392 bytes). Also, users shouldn't pay for features they don't use.

Breaking Changes:
The public behavior will remain unchanged. The exposed IEnumerable properties will return Empty collections.
However, users who depend on the internals and assume the underlying collection is List and is initialized, would need to update their code. For instance, some users have taken shortcuts and do this ((List<WhereExpressionInfo<T>>)spec.WhereExpressions).Add(...). This would be a breaking change for them.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0