Function Dispatch Tables in C (2019)
blog.alicegoldfuss.com
Function Dispatch Tables in C (2019)
1–10 of 52 posts
Re: Function Dispatch Tables in C (2019)
#2Re: Function Dispatch Tables in C (2019)
#3Re: Function Dispatch Tables in C (2019)
#4Re: Function Dispatch Tables in C (2019)
#5Re: Function Dispatch Tables in C (2019)
#6For performance, this is not necessary because the compiler can optimize long switch-case flow into dispatch tables: https://godbolt.org/z/7WxEfc6YM
Re: Function Dispatch Tables in C (2019)
#7I was expecting some form of benchmark to see if claims about better performance is true.
Regarding performance, if the CPU branch predictor works well the jump indirection overhead might disappear completely, but that's still not as good as if the compiler can inline the destination function, and jump tables usually prevent that.
(a switch-case dispatcher might actually be better than a traditional function pointer jump table, because the switch-case eliminates some function entry/exit "ceremony", also see "computed goto")
Re: Function Dispatch Tables in C (2019)
#8I was expecting some form of benchmark to see if claims about better performance is true.
I agree that a benchmark is warranted, or at least a comparison of the generated assembly (at different optimization levels).
Re: Function Dispatch Tables in C (2019)
#9Re: Function Dispatch Tables in C (2019)
#10I was expecting some form of benchmark to see if claims about better performance is true.
I'm also dubious on the claim the switch statement is O(n). It might be in a pathological worst case, but you can pretty much bet the compiler is going to transform it into a jump table or other optimized execution (maybe a computed jump). Especially when the cases are contiguous like this... I agree that a benchmark is warranted, or at least a comparison of the generated assembly (at different optimization levels).