ActiveLogin / ActiveLogin.Authentication

Support Swedish BankID (svenskt BankID) authentication in .NET. Unofficial package, not created by BankID.
https://activelogin.net
MIT License
214 stars 74 forks source link

Performance improvement in UAParser #462

Open stujo-eg opened 3 months ago

stujo-eg commented 3 months ago

Describe the bug The UAParser implementation seems to consume a lot of unnecessary memory, putting the ua yaml parse definition multiple times into memory.

What area is it related to UAParser

To Reproduce Steps to reproduce the behavior:

  1. Run any instance of activelogin
  2. Make sure you have a large amount of requests
  3. Perform a memory dump in VS with Managed heap Summary
  4. Observe many instances of 390.1 KB strings containing a YAML definition file for UAParser (problem)

Expected behavior Single read of parse definition

Screenshots image

NuGet package version 8.0.0

Runtime version .NET Core 8.0

Desktop (please complete the following information): N/A

Smartphone (please complete the following information): N/A

Additional context Parser uses Parser.GetDefault() for each detect which in turns reads manifest resource. Seems like this could easily be optimized by making the parser a static/singleton.

Activelogin https://github.com/ActiveLogin/ActiveLogin.Authentication/blob/main/src/ActiveLogin.Authentication.BankId.UAParser/UAParserDeviceDetector.cs

UaParser. https://github.com/ua-parser/uap-csharp/blob/master/UAParser/UAParser.cs

rfolkes commented 1 month ago

Thanks for reporting this! Will reproduce and have a look.