Performance question #85306
-
Since I don't now who to ask, hopefully someone sees this who can carry this forward (and understand IL code at an expert level). There is a Microsoft employee who has written a brilliant bit of code in terms of performance, for deep cloning. He has stopped work on it, perhaps someone else at Microsoft can pick it up and give c# this functionality. The github repository is: https://github.com/ReubenBond/DeepCopy If a performance evaluation is done on this code, it is extremely fast and efficient. This is a benchmark I have, as an example:
Perhaps an IL expert at Microsoft can keep this going and release it as a performance improvement for c#. I know that I and many other are using less efficient deepcopy/deepclone algorithms and would be glad to use something this efficient (especially for games development). Anyway, if possible to bring this kind of efficiency in c#, then I would be very grateful. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
General discussion of a library feature can be posted at dotnet/runtime.
There's no magic behind it. It just generates the same IL matches what you write to copy field by field.
Copying arbitrary fields from any type of objects not authored by you can be security concern. You can also see that |
Beta Was this translation helpful? Give feedback.
-
Transferring to runtime. |
Beta Was this translation helpful? Give feedback.
-
cc: @ReubenBond |
Beta Was this translation helpful? Give feedback.
-
For reference, doing the IClonable way is a lot of work. For safety, I am using the JSONSerialization for deep cloning as I do not have the knowledge of IL. However, if the IL way was the new standard for deep cloning, a lot of developers would use it due to the massive speed increase. Thanks for making this a discussion. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the information, that library was very impressive. I raised this issue as I thought it would help with the general C# push towards improved performance. I will stick with the JsonSerialization way as most of my use cases do not need extreme performance and therefore JsonSerialization is good enough and easy to reason as it is only a couple of lines of code (In my programming style, generally like POCO objects rather than ones that need attributes). I was really impressed with what you had done which is why I thought someone with expert IL knowledge would want to provide this kind of speed improvement to the general C# infrastructure. My motivation is for C# to have the best performance it can. |
Beta Was this translation helpful? Give feedback.
Thanks for the information, that library was very impressive.
I raised this issue as I thought it would help with the general C# push towards improved performance. I will stick with the JsonSerialization way as most of my use cases do not need extreme performance and therefore JsonSerialization is good enough and easy to reason as it is only a couple of lines of code (In my programming style, generally like POCO objects rather than ones that need attributes).
I was really impressed with what you had done which is why I thought someone with expert IL knowledge would want to provide this kind of speed improvement to the general C# infrastructure. My motivation is for C# to have the best per…