Investigating start-up slow-down in Entity Framework and Oracle

Recently, it came to our attention that one of the applications we are developing for a client shows a poor startup performance. It is a .NET application written in C# using Entity Framework and Oracle as the main data store.

The logical first step in diagnosing this issue was to run the application under a profiler. We used JetBrains’ dotTrace. It was rather surprising to see we burned over 20 seconds in Autofac resolution of the database context:

dotTrace screenshot

Using dotTrace to dig deeper into the call chain, the culprit seemed to be Oracle managed data provider for .NET. Judging by the method names, the provider was trying to find some kind for 20 seconds. Looking at the decompiled code provided by dotTrace, this call was made while parsing the application configuration.

dotTrace screenshot

Decompiled method

Since our application does not contain the config section mentioned in the code, we opened the machine.config file:

Machine config

Checking the path mentioned in the TNS_ADMIN setting we learned it was an invalid network path. And trying to open it in explorer took about 20 seconds. What a coincidence.

So we removed the setting. Unfortunately, this still hasn’t led to any improvements in our application’s start time.

According to Oracle’s documentation, the TNS_ADMIN setting can also be specified in a system variable. So we checked and found it there as well. However, removing it still hasn’t resolved the issue.

Since it wasn’t clear what other files the Oracle provider tried to access, it was time to fire up Process Monitor by SysInternals. Process monitor can show the real-time file system, registry, and process activity. We saw the following:

Process Monitor screenshot

So apparently there was even a registry key for this setting. Modifying this registry key finally resolved the issue. The application now starts about 30% faster just by correcting an invalid system setting.