✅ Class instantiation takes too long
Hello,
A class has many static properties, which are initialized in a static constructor so they’re set up when the first instance is created, and not when individual properties are accessed.
The issue is that there's a method called
I put the
I’m considering a hacky solution where I keep an internal counter and call
I have no idea what could cause this. Any feedback is appreciated.
Below are all the classes involved in the object creation:
A class has many static properties, which are initialized in a static constructor so they’re set up when the first instance is created, and not when individual properties are accessed.
The issue is that there's a method called
TryParse which takes way too long, despite having all static properties initialized. The first call to it takes about 3-4 seconds.I put the
TryParse method in the constructor, and here's the result:I’m considering a hacky solution where I keep an internal counter and call
TryParse only when the object is created for the first time.I have no idea what could cause this. Any feedback is appreciated.
Below are all the classes involved in the object creation:
- https://github.com/UaDetector/UaDetector/blob/main/src/UaDetector/UaDetector.cs
- https://github.com/UaDetector/UaDetector/blob/main/src/UaDetector/Parsers/BotParser.cs
- https://github.com/UaDetector/UaDetector/blob/main/src/UaDetector/Parsers/OsParser.cs
- https://github.com/UaDetector/UaDetector/blob/main/src/UaDetector/Parsers/BrowserParser.cs
- https://github.com/UaDetector/UaDetector/blob/main/src/UaDetector/Parsers/ClientParser.cs