Skip to content

Boundary function is too slow #9

@tabcat

Description

@tabcat

export const createIsBoundary: CreateIsBoundary = (
average: number,
level: number,
): IsBoundary => {
const limit = Number(MAX_UINT32 / BigInt(average));
return ({ seq, key }: Tuple) => {
const digest = sha256(encode([level, seq, key]));
return (
new DataView(digest.buffer, digest.byteOffset, 4).getUint32(0) < limit
);
};
};

The boundary function currently encodes each entry [level, seq, key] into CBOR to be hashed by sha256. The boundary function is called on any entry that is encoded or decoded so it's called constantly.

I'm going to try just converting the level and seq to bytes and then concatenating with the entry key, then hashing with sha256. Another option that might work is not using a hash function at all since the boundary test doesn't need to be secure.

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