Skip to content

PoH Performance degradation with rust 1.87+ #8869

@roryharr

Description

@roryharr

Problem

PoH performance degraded when upgrading from 1.86 to 1.87 compiler. This has blocked all future rust upgrades.

The disassembled code is fairly different between 1.86 and current nightly, so I can't comment on every instruction, but the biggest thing that jumped out to me in solana_sha256_hasher::hashv:
In the 1.86 version, there is only one dynamic call out:

_DYNAMIC+0x8a. This is sha2::sha256::compress256

However, in the newer versions there are two dynamic call outs:

_DYNAMIC+0x618: This is sha2::sha256::compress256
_DYNAMIC+0x620: This is solana_sha256_hasher::Hasher::result

Interesting! it appears that solana_sha256_hasher::Hasher::result is inlined in version 1.86, and it is no longer getting inlined in 1.87 and beyond.

I modified the library to add force inline to all function calls (Note to people following chat: Originally i tried this and it didn't work, but that was because I missed a function. After forcing all functions in the implementation it worked correctly).

1.86 without force inline

test bench_poh_hash                   ... bench:   1,397,297.50 ns/iter (+/- 4,870.21)

1.86 with force inline

test bench_poh_hash                   ... bench:   1,391,815.20 ns/iter (+/- 2,922.94)

nightly without force inline

test bench_poh_hash                   ... bench:   1,474,467.60 ns/iter (+/- 6,121.96)

nightly with force inline

test bench_poh_hash                   ... bench:   1,348,648.70 ns/iter (+/- 2,663.92)

Proposed Solution

Add force inline to all functions in impl Hasher in solana-sha256-hasher

Below shows performance with nightly
Before the restart, nightly without the fix is running.
After the restart, nightly with the fix is running.
It is also better than 1.86 (which is not shown on the graph)
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions