4 ms·
OOP in C inevitably leads to LOTS of pointer dereferencing. Pointer dereferencing hurts performance.
by 10GBps 5y ago
OOP in C inevitably leads to LOTS of pointer dereferencing. Pointer dereferencing hurts performance.
- vidarh 5y agoOOP in most languages tends to lead to lots of pointer dereferencing behind the scenes. If you're lucky and it's not much worse.
- rurban 5y agoOOP in C++ leads to twice as much pointer dereferencing. Just that you don't see it doesn't mean it does not exist. Look at the generated code. It sucks. The best thing in C++ is compile-time computation (ignoring the horrible template syntax). OO is not esp. well implemented.
- jcelerier 5y agoInlining the ctable into the object would only be faster if - you have very few objects - you have very few virtual functions If you have a lot of objects or a lot of virtual functions, things will be less likely to fit in cache which will entirely destroy your performance, by an order of magnitude when compared to a mostly-always-branch-predicted indirection. I remember experimenting with a an "inlined" version of std:: function and just having inlined the 5 ctor/move ctor/copy ctor/assignment operators was already slower than the vtable version when going through hundreds of callbacks ; imagine for something like Qt where QWidget or QGraphicsItem have 20+ virtual methods.
- rurban 5y agoDepends. My STL in C is faster by inlining the iterator methods. With something like glib or qt double indirection would be better of course, because these can be shared then. In my jitted ruby-like VM my methods are also copied, not referenced. Javascript also prefers copying the methods. This is usually called prototype-based OO. True prototypes copy the struct fields also, without creating classes, but copying the read-only methods only is a worthwhile OO optimization, C++ cannot do.
- jcelerier 5y agoCan you share some benchmarks for your STL ?