pmem / libpmemobj-cpp

C++ bindings & containers for libpmemobj
https://pmem.io
Other
107 stars 76 forks source link

Use self-relative ptrs in containers #181

Open igchor opened 5 years ago

igchor commented 5 years ago

Rationale

Current implementation of libpmemobj-cpp is based on persistent_ptr which is in fact a fat pointer. It stores PMEMoid which consists of two 64 bit fileds: pool_uuid and offset. Every dereference of peristent_ptr requires a call to pmemobj_direct function which calculates real address based on PMEMoid. Because of the nature of pmemobj_direct calls to this function cannot be optimized by the compiler and as a result using persistent_ptr is much slower than regular pointers.

Proposal

To address performance problems of peristent_ptr new pointer type with offset addressing model could be introduced. This new type of pointer would have only one 64 bit field: offset. Pointer value would be equal to offset + address of the pointer itself. This pointer would allow compiler to perform much better optimizations as no pmemobj function is required to be called during dereference. Additional benefit over persistent_ptr is smaller size.

The only limitation of this new type of pointer is that it cannot point to objects in another pool.

igchor commented 4 years ago

Ref: https://github.com/pmem/libpmemobj-cpp/pull/810

igchor commented 4 years ago

After implementing self_relative_ptr we should use it (or allow using it via template param) in cotnainers.