1.

Provide An Example Why Performance Improvements For Single-threaded Applications Can Cause Performance Degradation For Multi-threaded Applications.

Answer»

A prominent example for such optimizations is a List implementation that HOLDS the number of elements as a separate variable. This improves the PERFORMANCE for single-threaded applications as the size() operation does not have to iterate over all elements but can return the CURRENT number of elements directly. Within a multi-threaded APPLICATION the ADDITIONAL counter has to be guarded by a lock as multiple concurrent threads may insert elements into the list. This additional lock can cost performance when there are more updates to the list than invocations of the size() operation.

A prominent example for such optimizations is a List implementation that holds the number of elements as a separate variable. This improves the performance for single-threaded applications as the size() operation does not have to iterate over all elements but can return the current number of elements directly. Within a multi-threaded application the additional counter has to be guarded by a lock as multiple concurrent threads may insert elements into the list. This additional lock can cost performance when there are more updates to the list than invocations of the size() operation.



Discussion

No Comment Found