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

Implement caching of boxed values in ModelBase to decrease memory footprint #1437

Closed
GeertvanHorrik opened this issue Oct 11, 2019 · 8 comments · Fixed by #1438
Closed

Implement caching of boxed values in ModelBase to decrease memory footprint #1437

GeertvanHorrik opened this issue Oct 11, 2019 · 8 comments · Fixed by #1438
Assignees
Labels
Milestone

Comments

@GeertvanHorrik
Copy link
Member

@GeertvanHorrik GeertvanHorrik commented Oct 11, 2019

We've tried this before (see #1319). Seems I am in a better mood this evening getting this to work.

@GeertvanHorrik GeertvanHorrik added this to the 5.12.0 milestone Oct 11, 2019
@GeertvanHorrik GeertvanHorrik self-assigned this Oct 11, 2019
@GeertvanHorrik

This comment has been minimized.

Copy link
Member Author

@GeertvanHorrik GeertvanHorrik commented Oct 11, 2019

It's not necessarily faster, but does have a better memory footprint, so will see if we can get all the tests to succeed with this one.

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Oct 11, 2019

So I looked into #1319 a bit and the behavior looks awfully close to something similar to what we have built but it uses precompiled Expression Trees. The setter is either an Action<T> (untyped) or Action<T, TReturn> (strongly typed) and the Getter is either a Func<T> (untyped) or Func<T, TReturn> (strongly typed).

There are two higher level methods that can create all setters and getters for an input class (cached in an IReadOnlyDictionary with the PropertyName as a key stored as a case insensitive string). FastExpressionCompiler is used to speed up the compiling of the expressions but as it's only ran once the only expense is the cold start, you can reference from the dictionary going forward.

We use this method for everything from projecting an IDataReader to a strongly typed object to dynamic property handling.

Is this something that might interest you?

@GeertvanHorrik

This comment has been minimized.

Copy link
Member Author

@GeertvanHorrik GeertvanHorrik commented Oct 11, 2019

So I looked into #1319 a bit and the behavior looks awfully close to something similar to what we have built but it uses precompiled Expression Trees. The setter is either an Action<T> (untyped) or Action<T, TReturn> (strongly typed) and the Getter is either a Func<T> (untyped) or Func<T, TReturn> (strongly typed). ...

@vaecors absolutely!

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Oct 11, 2019

@GeertvanHorrik I’m actually working on a PoC. I had a few ideas. When I’m confident with it will push up a repo.

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Oct 11, 2019

@GeertvanHorrik Alright so that PoC did not end up where I was hoping. However I have gone ahead and put up a gist of an expression tree builder utility class that does both untyped and typed setters and getters. You may be able to find some use for it. It does require the FastExpressionCompiler library as a dependency.

GeertvanHorrik added a commit that referenced this issue Oct 12, 2019
@GeertvanHorrik

This comment has been minimized.

Copy link
Member Author

@GeertvanHorrik GeertvanHorrik commented Oct 12, 2019

See #1438 for the PR implementing this change. Will see if I can use the expression stuff as well, but prefer to keep Catel.Core dependency-less.

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Oct 12, 2019

The FastExpressionCompiler is an optional behavioral change and is not necessarily required for those methods. We used it to speed up cold starts and the fact the library it sits in already depends on it due to our use of Mapster. I made about one comment concerning one of the changes. I also was a bit curious of the use of IsValueType vs IsPrimitive type for one of the calling methods but that's more of a preference I feel more than an advantage of A vs B.

@lock

This comment has been minimized.

Copy link

@lock lock bot commented Oct 17, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 17, 2019
@GeertvanHorrik GeertvanHorrik added feature and removed improvement labels Oct 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
1 participant
You can’t perform that action at this time.