-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
arch-wasmWebAssembly architectureWebAssembly architecturearea-System.RuntimeenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additionslinkable-frameworkIssues associated with delivering a linker friendly frameworkIssues associated with delivering a linker friendly framework
Milestone
Description
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter type is always required by System.Private.CoreLib because it's used for resources serialization/deserialization. The required code after trimming in size sensitive scenarios ends up quite small (about 6kB) which indicates there is not a large chunk of code to be moved.
Moving the implementation would help reduce the number of file transfers for browser and get rid of extra reflection call in
runtime/src/libraries/System.Private.CoreLib/src/System/Resources/ResourceReader.Core.cs
Lines 68 to 86 in 9907151
| private void InitializeBinaryFormatter() | |
| { | |
| LazyInitializer.EnsureInitialized(ref s_binaryFormatterType, () => | |
| Type.GetType("System.Runtime.Serialization.Formatters.Binary.BinaryFormatter, System.Runtime.Serialization.Formatters, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", | |
| throwOnError: true)!); | |
| LazyInitializer.EnsureInitialized(ref s_deserializeMethod, () => | |
| { | |
| MethodInfo binaryFormatterDeserialize = s_binaryFormatterType!.GetMethod("Deserialize", new Type[] { typeof(Stream) })!; | |
| // create an unbound delegate that can accept a BinaryFormatter instance as object | |
| return (Func<object?, Stream, object>)typeof(ResourceReader) | |
| .GetMethod(nameof(CreateUntypedDelegate), BindingFlags.NonPublic | BindingFlags.Static)! | |
| .MakeGenericMethod(s_binaryFormatterType) | |
| .Invoke(null, new object[] { binaryFormatterDeserialize })!; | |
| }); | |
| _binaryFormatter = Activator.CreateInstance(s_binaryFormatterType!)!; | |
| } |
Metadata
Metadata
Assignees
Labels
arch-wasmWebAssembly architectureWebAssembly architecturearea-System.RuntimeenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additionslinkable-frameworkIssues associated with delivering a linker friendly frameworkIssues associated with delivering a linker friendly framework