Kenn
Kenn

Reputation: 2479

Performance of reading a registry key?

I'm wondering how long it takes (in milliseconds) to read a registry value from the Windows registry through standard C# libraries. In this case, I'm reading in some proxy settings.

What order of magnitude value should I expect? Are there any good benchmark data available?

I'm running WS2k8 R2 amd64. Bonus points: How impactful is the OS sku/version on this measure?

 using (RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Software/Copium")) 
 { 
      return (string)registryKey.GetValue("BinDir"); 
 } 

Upvotes: 6

Views: 5649

Answers (2)

pstrjds
pstrjds

Reputation: 17448

This blog post from Raymond Chen should prove helpful: The performance cost of reading a registry key

I would add that in general, it is not recommended to store settings in the registry for C# apps, use persisted storage, or a config file or something of that nature. There are problems related to permissions when you deal with the registry. Reading is often not an issue, but if you are going to persist things then it gets hairy, especially with UAC and newer OSs that shadow copy things.

Upvotes: 3

Preet Sangha
Preet Sangha

Reputation: 65546

I cannot quote numbers as I don't know. But having just read 30 pages in the Windows Internals 5 book about the registry the following noteworthy things that I didn't know became clear.

  • The Registry is transactional and has fail safes to prevent from being corrupted. This can affect performance. Since the transactional level is read committed, reads shouldn't be blocked by writes so they should be performant.

  • The registry is cached in memory (well frequently used values anyway) so if you access a set of keys often the performance should remain stable after the first hit.

Upvotes: 11

Related Questions