Skip to content

Refactor dynamic allocator #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Robbepop opened this issue Nov 17, 2019 · 1 comment
Closed

Refactor dynamic allocator #245

Robbepop opened this issue Nov 17, 2019 · 1 comment
Labels
A-ink_storage [ink_storage] Work Item

Comments

@Robbepop
Copy link
Collaborator

Robbepop commented Nov 17, 2019

The current Flush and dynamic storage has problems in that dynamically allocated storage entities cannot be properly deallocated from storage because of a missing global accessor to the dynamic storage allocator as well as a missing accessor to the flusher.

We have to fix both problems while maintaining the efficiency gains through the new ink_core::env2.

Global Instance

The only solution I currently see is that we introduce a globally accesible object that handles dynamic storage allocations and deallocations. This is a major move from the internal DynEnv approach that we have right now that tightly encapsulates the dynamic environment which enables us to perfectly reuse our internal buffers to avoid many (re-)allocations on the heap. However, this system does not allow access from anywhere and requires to have references from anywhere in order to allow for generic and ubiquitous operations such as deallocation (Drop) and flushing (through Flush trait).

Buffer Pool

In order to maintain efficiency a solution might be to introduce a global buffer pool that is accessible from anywhere through shared references (&self) and enables buffer reusing. It is basically a pool of buffers that allow for intermediate buffer usages from anywhere to avoid heap allocations.

A possible interface for this could be:

/// Returns a reference to a shared buffer.
/// Shared buffers are generally a `Vec<u8>` under the hood and allow to store intermediate results.
/// When such a `SharedBuffer` is dropped (through its `Drop`) impl it is returned back to the `BufferPool` for later reuse.
fn get_buffer(&self) -> SharedBuffer;

The major problem is what the exact lifetime of such a returned SharedBuffer shall be optimally. We don't want them to be stored anywhere for an extended period of time since they are generally meant to be used as intermediate buffers. So we should attach some lifetime to them in the way how RefCell does that through RefMut etc.

@Robbepop Robbepop self-assigned this Nov 17, 2019
@Robbepop Robbepop added the A-ink_storage [ink_storage] Work Item label Nov 17, 2019
@Robbepop Robbepop removed their assignment Nov 17, 2019
@Robbepop Robbepop changed the title Refactor Flush system Refactor dynamic allocator Nov 20, 2019
@Robbepop
Copy link
Collaborator Author

The #311 introduced a new dynamic storage allocator that actually works. The only thing left is a follow-up to introduce and use a so-called PushOnDrop abstractions but the rest already works as expected for the new storage2 module. Closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ink_storage [ink_storage] Work Item
Projects
None yet
Development

No branches or pull requests

1 participant