Hidden boxing in BCL?

I recently found out that in BCL there are some parts that still use some "obsolete" code, which was probably written before the generics were introduced in version 2.0 of the framework. Apparently, parts of this "old" code can cause the CLR to perform numerous boxing / unpacking operations.

Since overuse of boxing is never good, I wanted to know if there are any other critical places in BCL that you notice that boxing is happening? Thanks

+2
source share
3 answers

Note that for the specified specific example:

  • DateTime.Now calls a system function at a significantly higher cost than boxing for int (even taking into account the increased gen0 collection frequency associated with it).
  • Dateime.Now accuracy is extremely low on Windows platforms (in most cases, 10-15 ms)
    • Thus, calling this function is not very useful if you are doing this, most likely you are doing something else wrong ...

Thus, you should only worry about this if your profiling indicates that this is a problem.
Since MS never bothered to fix it, it would seem unlikely that it would ever arise as a problem for any customers.

More care for you in a hidden vein, most likely, will be:

But then again, all this (except, perhaps, to be listed as a key dictionary, requiring considerable effort to work) should only be allowed if you need to

+3
source

Firstly, you are right - this is not good. But tearing off the dot net will not do you any good - you should take the framework infrastructure as you are and hope for future optimization (for example, TransactionScope , which were optimized from 2.0 to 3.5 SP1).

Hope this cleared.

+2
source

Knowledge gives you strength.

I recently learned how the "path" + "\" + "file_name" is implemented.

The middle character '\' is first placed in the object, then Concat (object, object, object) is called, then ToString is called three times, and then Concat (line, line, line) is called.

If you, the programmer, knew that he / she could write: "path" + "\" + "filename"

0
source

All Articles