Skip to main content
Topic: foobar2000 SDK suggestions (Read 302 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

foobar2000 SDK suggestions

@Peter: while creating STL wrappers for pfc containers I found a weird piece of code:
Code: [Select]
T pfc::list_base_const_t::operator[](t_size n) const {
    T temp;
    get_item_ex(temp,n);
    return std::move(temp);
}

For some reason this operator returns by value instead of reference, resulting in a needless constructor call every time an element is accessed.

Another thing that is present in this method and in some other parts of SDK is `return std::move(...);`: such return prevents Return Value Optimization and results in a needless object creation/move. `std::move` should be removed for RVO to function properly (which is actually guaranteed by C++17 in this case).

On entirely different note: while I was refactoring my code, I've found out that your `pfc::sort_t` is much better than `std::sort` (43% faster)! Really great job! But recently I've stumbled upon an interesting sorting algorithm called `timsort`, which does an excellent job at sorting arrays of strings and non-integral types (e.g. metadb_handle_list_helper::sort_by_relative_path):
Code: [Select]
sort_by_relative_path:

4.8k sorted elements.
Sort_Std Time: 27 msec
Sort_Pfc Time: 33 msec
Sort_Tim Time: 13 msec

4.8k uniformally distributed elements.
Sort_Std Time: 46 msec
Sort_Pfc Time: 32 msec
Sort_Tim Time: 31 msec

20k partially sorted (every 10% block is sorted).
Sort_Std Time: 239 msec
Sort_Pfc Time: 174 msec
Sort_Tim Time: 77 msec

20k uniformally distributed elements.
Sort_Std Time: 255 msec
Sort_Pfc Time: 178 msec
Sort_Tim Time: 168 msec
Benchmark was performed using the following `timsort` implementation: https://github.com/tvanslyke/timsort-cpp

Anyways, I hope at least some part of this would be useful to you. Keep up the good job and have a nice day =)

Re: foobar2000 SDK suggestions

Reply #1
Re list_base_const_t-
You will find many weird things in this PFC list code. Some of them are results of my lack of knowledge 15 years ago when this code was created and cannot be altered because of compatibility requirements.
When making most of PFC code I did knot know about Return Value Optimization, hence *classes* instead of functions for things that return a string... I should have investigated it back then instead of rage-coding what seemed to guarantee the intended behavior. That said, the std::move() is indeed unnecessary; I will audit PFC for spurious std::move()s and remove them.
pfc::list_base_const_t<> does not ever return references, because it was designed to allow an implementation which generates the objects on-demand instead of actually holding their instances. Which probably hasn't been done for the last decade, but the interface cannot be altered in any way - fb2k component ABI depends on it.

Re sorting
PFC does one thing different than everyone else - int compare(val1, val2) instead of the bool predicate.
For certain objects this may be considerably faster.
However, for most things, I find VC STL code to be faster.
One essential thing to keep in mind when benchmarking STL- it is notorious for being unusably slow when compiled in debug mode due to debug checks - always benchmark release builds.

Current fb2k SDK has a new sort function which is multithreaded, abortable and intended for sorting huge numbers of audio tracks - search for 'foosort' under 'SDK'.

Re: foobar2000 SDK suggestions

Reply #2
cannot be altered because of compatibility requirements
Ugh... You have my sympathies... Maintaining compatibility with ancient ABI is such a huge pain in the butt...

Re sorting
However, for most things, I find VC STL code to be faster.
One essential thing to keep in mind when benchmarking STL- it is notorious for being unusably slow when compiled in debug mode due to debug checks - always benchmark release builds.
Haha, well I'm not a fan of benchmarking on Debug build =)
All tests were done with all optimizations enabled (WholeProgramOptimization, EnableCOMDATFolding and etc).
`timsort` vs `std::sort` comparison was done multiple time by multiple parties, so results are not really surprising: timsort is actually used in Python, Java and Android as a default algorithm for scenarios such as the one described above.

Current fb2k SDK has a new sort function which is multithreaded, abortable and intended for sorting huge numbers of audio tracks - search for 'foosort' under 'SDK'.
This one is actually already on my to-do list =)

 
SimplePortal 1.0.0 RC1 © 2008-2018