-
Notifications
You must be signed in to change notification settings - Fork 14
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
Rkuris/cache read strategy expose to ffi #791
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Has a decent impact to the load times on my mac: $ cargo run --profile maxperf --bin benchmark -- -n 100 create Finished `maxperf` profile [optimized] target(s) in 0.33s Running `target/maxperf/benchmark -n 100 create` [2025-02-12T20:27:46Z INFO benchmark::create] Generated and inserted 100 batches of size 10000 in 9s 981ms $ cargo run --profile maxperf --bin benchmark -- -n 100 -C branch-reads create Finished `maxperf` profile [optimized] target(s) in 0.14s Running `target/maxperf/benchmark -n 100 -C branch-reads create` [2025-02-12T20:29:58Z INFO benchmark::create] Generated and inserted 100 batches of size 10000 in 10s 179ms $ cargo run --profile maxperf --bin benchmark -- -n 100 -C all create Finished `maxperf` profile [optimized] target(s) in 0.33s Running `target/maxperf/benchmark -n 100 -C all create` [2025-02-12T20:27:29Z INFO benchmark::create] Generated and inserted 100 batches of size 10000 in 12s 596ms
Some were in the flattened structure, others were not.
Adds an additional required uint8_t to the ffi database open, which is now accessible from firewood.go, but it currently hardcodes it to zero (the default). Fixed up the README as there is no longer a makefile as the doc describes
Updated documentation as well. To create a database, you now should do: db := NewDatabase(WithPath("somewhere.db"), WithCreate(true)) This exposes a few new options, such as the number of revisions, the size of the cache, and the read cache strategy. The documentaton provides more details... The following is from `go doc -all`: package firewood // import "github.com/ava-labs/firewood/ffi/v2" TYPES type Firewood struct { // Has unexported fields. } Firewood is a handle to a Firewood database func NewDatabase(options ...OpenOption) Firewood NewDatabase opens or creates a new Firewood database with the given options. Returns a handle that can be used for subsequent database operations. func (f *Firewood) Batch(ops []KeyValue) []byte func (f *Firewood) Close() error Close closes the database and releases all held resources. func (f *Firewood) Commit(root []byte) error Commit does nothing, since update already persists changes func (f *Firewood) Get(input_key []byte) ([]byte, error) Get retrieves the value for the given key. func (f *Firewood) Prefetch(key []byte) ([]byte, error) Prefetch does nothing since we don't need to prefetch for firewood func (f *Firewood) Root() []byte Root returns the current root hash of the trie. func (f *Firewood) Update(keys, vals [][]byte) ([]byte, error) Update batches all the keys and values and applies them to the database type KeyValue struct { Key []byte Value []byte } KeyValue is a key-value pair type OpenConfig struct { // Has unexported fields. } OpenConfig is used to configure the database at open time type OpenOption func(*OpenConfig) OpenOption is a function that configures the database at open time func WithCreate(create bool) OpenOption WithCreate sets whether to create a new database If false, the database will be opened If true, the database will be created func WithNodeCacheEntries(entries uintptr) OpenOption WithNodeCacheEntries sets the number of node cache entries func WithPath(path string) OpenOption WithPath sets the path for the database func WithReadCacheStrategy(strategy int8) OpenOption WithReadCacheStrategy sets the read cache strategy 0: Only writes are cached 1: Branch reads are cached 2: All reads are cached func WithRevisions(revisions uintptr) OpenOption WithRevisions sets the number of revisions to keep
darioush
approved these changes
Feb 12, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds an additional required uint8_t to the ffi database open, which is now accessible from firewood.go, but it currently hardcodes it to zero (the default).
Fixed up the README as there is no longer a makefile as the doc describes