Skip to content

Commit

Permalink
perf: Add GetBootTime binding
Browse files Browse the repository at this point in the history
  • Loading branch information
ebariche committed Apr 4, 2023
1 parent 6607df4 commit 8309a5c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/Input/PointerRoutedEventArgs.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private PointerPointProperties GetProperties()

private static ulong ToTimeStamp(double timestamp)
{
_bootTime ??= (ulong)(double.Parse(WebAssemblyRuntime.InvokeJS("Date.now() - performance.now()"), CultureInfo.InvariantCulture) * TimeSpan.TicksPerMillisecond);
_bootTime ??= (ulong)(WindowManagerInterop.GetBootTime() * TimeSpan.TicksPerMillisecond);

return _bootTime.Value + (ulong)(timestamp * TimeSpan.TicksPerMillisecond);
}
Expand Down
11 changes: 11 additions & 0 deletions src/Uno.UI/UI/Xaml/WindowManagerInterop.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ internal static string FindLaunchArguments()
WebAssemblyRuntime.InvokeJS("Uno.UI.WindowManager.findLaunchArguments()");
#endif

internal static double GetBootTime()
=>
#if NET7_0_OR_GREATER
NativeMethods.GetBootTime();
#else
double.Parse(WebAssemblyRuntime.InvokeJS("Date.now() - performance.now()"), CultureInfo.InvariantCulture);
#endif

#region CreateContent
internal static void CreateContent(IntPtr htmlId, string htmlTag, IntPtr handle, int uiElementRegistrationId, bool htmlTagIsSvg, bool isFocusable)
{
Expand Down Expand Up @@ -1294,6 +1302,9 @@ internal static partial void ArrangeElement(
[JSImport("globalThis.Uno.UI.WindowManager.findLaunchArguments")]
internal static partial string FindLaunchArguments();

[JSImport("globalThis.Uno.UI.WindowManager.getBootTime")]
internal static partial double GetBootTime();

[JSImport("globalThis.Uno.UI.WindowManager.current.focusView")]
internal static partial void FocusView(IntPtr htmlId);

Expand Down
7 changes: 7 additions & 0 deletions src/Uno.UI/ts/WindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ namespace Uno.UI {
}
}

/**
* Estimated application startup time
*/
public static getBootTime(): number {
return Date.now() - performance.now();
}

/**
* Create a html DOM element representing a Xaml element.
*
Expand Down

0 comments on commit 8309a5c

Please sign in to comment.