Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the Specification size. Set the initial state to null. #415

Closed
Tracked by #427
fiseni opened this issue Nov 9, 2024 · 0 comments · Fixed by #441
Closed
Tracked by #427

Reduce the Specification size. Set the initial state to null. #415

fiseni opened this issue Nov 9, 2024 · 0 comments · Fixed by #441
Assignees

Comments

@fiseni
Copy link
Collaborator

fiseni commented Nov 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant