wolfpld / tracy

Frame profiler
https://tracy.nereid.pl/
Other
9.87k stars 658 forks source link

Fix ThreadData-sorting bug. #879

Closed mcourteaux closed 2 weeks ago

mcourteaux commented 3 weeks ago

For a detailed analysis of what was the bug, see #875. Closes #875. But in summary, the bug is due to the fact the sorting code assumes any difference in number of items in m_threadOrder and worker.GetThreadData() is exclusively due to the elements in the end of Worker::GetThreadData(). On the surface, this is true, but the erasing logic to process Thread Hints breaks this assumed invariant.

mcourteaux commented 3 weeks ago

@wolfpld New fix: keep a separate list of those that are to be reinserted. Process those first, such that the remaining ones again must be new and therefore found at the end of the workers thread-data vector. The new list avoids having to do an O(n²) search to figure out which threads in the workers thread-data list are missing in threadOrder.