A way to retrieve a specific value without ctor overhead #2773
-
In realm-dotnet, there is a GC/alloc overhead associated with traversal. An example usage which can be quite expensive is as such: var cats = realm.All<Cat>();
var list = new List<string>();
foreach (var c in cats)
list.Add(c.NameTag.Name); Even though we are only interested in the cat's name, this will construct every Is there any way to do this kind of query more efficiently? I've tried to find a method using the dynamic API but it doesn't seem readily possible. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 12 replies
-
There isn't a way to do this more efficiently, I'm afraid. I have had the idea of allowing realm models to be value types, which should help reduce GC overhead, but there would still be the matter of performing the P/Invoke calls to get the I think in this case supporting something like |
Beta Was this translation helpful? Give feedback.
There isn't a way to do this more efficiently, I'm afraid. I have had the idea of allowing realm models to be value types, which should help reduce GC overhead, but there would still be the matter of performing the P/Invoke calls to get the
Cat
andNameTag
handles.I think in this case supporting something like
realm.All<Cat>().Select(c => c.NameTag.Name).ToList()
would be ideal, and it'd be worth looking into what the Swift SDK did for the Projections feature they released recently.