You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For analysis activities with multiple parameters, especially if they occur frequently in the game, gc will be generated.
Currently, parameters are not suitable for reuse, so they are constantly recreated unnecessarily and cause boxing. However, after being passed to the LogEvent method, they are passed to StringList and VariantList and the job is done. They can be reused if type safety is ensured. At the same time, the Parameter.Value is subject to boxing and unboxing.
My suggestion is to solve both the boxing problem and create reusable parameter types with a small change in the Parameter class. This change will also not break the old usage and will provide backward compatibility.
Edit the parameter class as follows. This maintains backward compatibility and also allows us to create versions that avoid boxing that are reusable.
publicclassParameter{// Make public instead of internalpublicstringName{get;set;}// Make private instead of internal.objectValue{get;set;}// Add to be able to create types that help us avoid boxing.internalvirtualVariantConvertToVariant(){returnVariant.FromObject(Value);}protectedParameter(){}publicParameter(stringparameterName,longparameterValue):this(parameterName,(object)parameterValue){}publicParameter(stringparameterName,doubleparameterValue):this(parameterName,(object)parameterValue){}publicParameter(stringparameterName,stringparameterValue):this(parameterName,(object)parameterValue){}publicParameter(stringparameterName,IDictionary<string,object>parameterValue):this(parameterName,(object)parameterValue){}publicParameter(stringparameterName,IEnumerable<IDictionary<string,object>>parameterValue):this(parameterName,(object)parameterValue){}privateParameter(stringname,objectvalue){Name=name;Value=value;}}
publicstaticclassFirebaseAnalytics{// Add a list option and use the Parameter.ConvertToVariant method instead of Variant.FromObject when passing it to VariantList.// Use for instead of foreach.publicstaticvoidLogEvent(stringname,List<Parameter>parameters){StringListstringList=newStringList();VariantListvariantList=newVariantList();for(inti=0;i<parameters.Count;i++){Parameterparameter=parameters[i];stringList.Add(parameter.Name);//Use ConvertToVariant instead of Variant.FromObjectvariantList.Add(parameter.ConvertToVariant());}FirebaseAnalyticsInternal.LogEvent(name,stringList,variantList);}}
3. Create types that can be reused and avoid boxing.
new Parameter(string name, IDictionary<string, object) new Parameter(string name, IEnumerable<IDictionary<string, object>)
Optimized codes for these two types are ready, but I am not writing them here for now to avoid confusion. My priority is for you to add the types above. If you are interested, I can also put the optimized codes of both types here. Just let me know.
5. Usage
Now we can cache parameters as we wish and avoid constantly allocating memory.
Description
For analysis activities with multiple parameters, especially if they occur frequently in the game, gc will be generated.
Currently, parameters are not suitable for reuse, so they are constantly recreated unnecessarily and cause boxing. However, after being passed to the LogEvent method, they are passed to StringList and VariantList and the job is done. They can be reused if type safety is ensured. At the same time, the Parameter.Value is subject to boxing and unboxing.
My suggestion is to solve both the boxing problem and create reusable parameter types with a small change in the Parameter class. This change will also not break the old usage and will provide backward compatibility.
API Proposal
1. Edit Parameter.cs
Edit the parameter class as follows. This maintains backward compatibility and also allows us to create versions that avoid boxing that are reusable.
2. Edit FirebaseAnalytics.cs
3. Create types that can be reused and avoid boxing.
4 Optional: Support Dictionary Types
new Parameter(string name, IDictionary<string, object)
new Parameter(string name, IEnumerable<IDictionary<string, object>)
Optimized codes for these two types are ready, but I am not writing them here for now to avoid confusion. My priority is for you to add the types above. If you are interested, I can also put the optimized codes of both types here. Just let me know.
5. Usage
Now we can cache parameters as we wish and avoid constantly allocating memory.
Firebase Product(s)
Analytics
Targeted Platform(s)
No response
The text was updated successfully, but these errors were encountered: