ClickHouse / clickhouse-cpp

C++ client library for ClickHouse
Apache License 2.0
305 stars 159 forks source link

optimize #340

Closed 1261385937 closed 1 year ago

1261385937 commented 1 year ago

Too many virtual function now :smile:. So add keyword 'final' for possible "de-virtualization" compiler optimize. Most of the time, it is effective.

1261385937 commented 1 year ago
class A {
public:
    virtual void f() = 0;
};

class B final: public A {
public:
    void f() override;
};

class C : public A {
public:
    void f() override;
};

void foo(B& b) {
    b.f();
}

void bar(C& c) {
    c.f();
}

and the simple asm

bar(C&):
        mov     rax, QWORD PTR [rdi]
        jmp     [QWORD PTR [rax]]
foo(B&):
        jmp     B::f()
Enmk commented 1 year ago

Hi @1261385937, thank you for the contribution!

Do you see any difference in performance and/or assembly after applying this patch?

1261385937 commented 1 year ago

@Enmk

After days and nights of testing, the results have shown no significant improvement. ~~ :stuck_out_tongue_closed_eyes:

Enmk commented 1 year ago

After days and nights of testing, the results have shown no significant improvement.

I believe that we might not need this optimization. Because benefits are negligible, and it also changes user-facing API, potentially breaking customer's code.

1261385937 commented 1 year ago

The results have shown no significant improvement. Close