Skip to content

Increase C++ performance in Lesson 265 #516

@KlasterK

Description

@KlasterK

LTO

In Rust, LTO is enabled:

lto = "fat"            # Enables full link-time optimization for better inlining and dead code elimination across crates.

While in C++ it isn't. Add this flag in CMakeLists:

set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)

TUs count

In Rust version, there's only one TU, main.rs. While in C++ we have 5 files, and without LTO, inlines are not possible. LTO will fix TUs count problem, but maybe it will be even better to keep the code in 1 TU like in Rust version.

Compilers

C++ version may use different compilers depending on platform and toolchain. rustc is based on LLVM, so C++ should be compiled with a compiler based on LLVM too, which is clang++. Add an LLVM toolchain so compilers won't differ across platforms.

P.S. I didn't watch the video, a fellow of mine shared the comparison of C++ and Rust results and I started digging and noticed these omissions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions