firebase-unity-sdk icon indicating copy to clipboard operation
firebase-unity-sdk copied to clipboard

[FR]: Add ReadOnlySpan-based overload for FirebaseAnalytics.LogEvent

Open abogarsukov-braingames opened this issue 1 year ago • 2 comments

Description

Currently there are overloads of the FirebaseAnalaytics.LogEvent for a single parameter and array of parameters. In most cases this is suboptimal as each event requires allocating an array of parameters. Adding an overload accepting ReadOnlySpan<Parameter> would help developers avoid unnecessary allocations.

API Proposal

Add a new LogEvent overload like this:

public unsafe static void LogEvent(string name, ReadOnlySpan<Parameter> parameters)
{
    IntPtr[] array = new IntPtr[parameters.Length];
    for (int i = 0; i < parameters.Length; i++)
    {
        array[i] = (IntPtr)Parameter.getCPtr(parameters[i]);
    }

    fixed (IntPtr* ptr = array)
    {
        FirebaseAnalyticsPINVOKE.LogEvent__SWIG_5(name, (IntPtr)ptr, parameters.Length);
        if (AppUtilPINVOKE.SWIGPendingException.Pending)
        {
            throw AppUtilPINVOKE.SWIGPendingException.Retrieve();
        }
    }
}

Firebase Product(s)

Analytics

Targeted Platform(s)

Apple Platforms, Android, Desktop

abogarsukov-braingames avatar May 03 '24 08:05 abogarsukov-braingames

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar May 03 '24 08:05 google-oss-bot

Hi @abogarsukov-braingames, thanks for suggesting a feature request! This does seem like an efficient way of handling allocations. That said, I'll go ahead and mark this as a feature request, and bring this up to our engineering sync to see if we can get some feedback. While we are unable to promise any timeline for this, we'll definitely keep this under our radar.

argzdev avatar May 03 '24 09:05 argzdev