Skip to content

RFC: Add batch read/write APIs to reduce JS<->C++ overhead #863

@IberAI

Description

@IberAI

Hi thank you this library is already blazingly fast. Im not an expert but Im wondering if adding a simple way to batch multiple reads/writes into a single native operation could further improve performance?

Idea: collapse N JS <-> native calls into 1 do the work natively and coalesce change events

I was thinking it would look something like this when you use it

// Write a bunch of values at once
storage.setMany([
  ['loggedIn', true],
  ['user:id', 1234],
  ['user:name', 'Ada'],
])

// Read multiple keys with one call
const { ['user:id']: id, ['user:name']: name } = storage.getMany(['user:id', 'user:name'])

// Delete multiple keys efficiently
storage.deleteMany(['tmp:1', 'tmp:2', 'tmp:3'])

// Coalesce event emissions & native calls
storage.batch(() => {
  storage.setMany([
    ['features:welcome', true],
    ['features:newHome', false],
  ])
  storage.deleteMany(['legacy:flag'])
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions