aptos-labs / aptos-core

Aptos is a layer 1 blockchain built to support the widespread use of blockchain through better technology and user experience.
https://aptosfoundation.org
Other
6.04k stars 3.61k forks source link

Redundant atomic references in `DbReaderWriter` #13464

Open mzabaluev opened 3 months ago

mzabaluev commented 3 months ago

Performance issue

In aptos-storage-interface, the DbReaderWriter uses two Arc fields, seemingly only to achieve dynamic dispatch via DbReader and DbWriter for the same object: https://github.com/aptos-labs/aptos-core/blob/11033f4dd27144908ad9832dd49dc86fe261561f/storage/storage-interface/src/lib.rs#L549

This seems unnecessary; a helper trait could combine both vtables without the overhead of an extra reference, furthermore you could use Box<dyn DbReaderWriter> if you don't need atomic reference counting at all:

trait DbReaderWriter: DbReader + DbWriter {}

impl<T: DbReader + DbWriter> DbReaderWriter for T {}
mzabaluev commented 3 months ago

A minor thing to consider while changing all the object type pointers: impl MoveStorage for &dyn DbReader could be more ergonomically implemented on the unsized dyn DbReader instead.

github-actions[bot] commented 1 month ago

This issue is stale because it has been open 45 days with no activity. Remove the stale label or comment - otherwise this will be closed in 15 days.

mzabaluev commented 1 month ago

bump