Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-pousette committed Dec 27, 2024
1 parent 72112c9 commit 8987494
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 39 deletions.
51 changes: 15 additions & 36 deletions packages/programs/data/document/document/benchmark/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { field, option, variant } from "@dao-xyz/borsh";
import { Program, type ProgramClient } from "@peerbit/program";
import { TestSession } from "@peerbit/test-utils";
import B from "benchmark";
import crypto from "crypto";
import * as B from "tinybench";
import { v4 as uuid } from "uuid";
import { Documents, type SetupOptions } from "../src/program.js";

Expand Down Expand Up @@ -68,41 +68,20 @@ await client.open(store, {
},
});

const resolver: Map<string, () => void> = new Map();
store.docs.events.addEventListener("change", (change) => {
change.detail.added.forEach((doc) => {
resolver.get(doc.id)!();
resolver.delete(doc.id);
const suite = new B.Bench({ name: "put", warmupIterations: 1000 });
suite.add("put", async () => {
const doc = new Document({
id: uuid(),
name: "hello",
number: 1n,
bytes: crypto.randomBytes(1200),
});
await store.docs.put(doc, {
unique: true,
});
});

const suite = new B.Suite();
suite
.add("put", {
fn: async (deferred: any) => {
const doc = new Document({
id: uuid(),
name: "hello",
number: 1n,
bytes: crypto.randomBytes(1200),
});
resolver.set(doc.id, () => {
deferred.resolve();
});
await store.docs.put(doc, { unique: true });
},

minSamples: 300,
defer: true,
})
.on("cycle", (event: any) => {
console.log(String(event.target));
})
.on("error", (err: any) => {
throw err;
})
.on("complete", async function (this: any, ...args: any[]) {
await store.drop();
await session.stop();
})
.run();
await suite.run();
console.table(suite.table());
await store.drop();
await session.stop();
12 changes: 10 additions & 2 deletions packages/programs/data/shared-log/src/ranges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,7 @@ export const getSamples = async <R extends "u32" | "u64">(
let matured = 0;

/* let missingForCursors: NumberFromType<R>[] = [] */
let uniqueVisited = new Set<string>();
for (let i = 0; i < cursor.length; i++) {
let point = cursor[i];

Expand All @@ -1615,6 +1616,7 @@ export const getSamples = async <R extends "u32" | "u64">(
);

for (const rect of allContaining) {
uniqueVisited.add(rect.value.hash);
let prev = leaders.get(rect.value.hash);
if (!prev) {
if (isMatured(rect.value, now, roleAge)) {
Expand All @@ -1626,8 +1628,13 @@ export const getSamples = async <R extends "u32" | "u64">(
}
}

if (options?.uniqueReplicators?.size === leaders.size) {
break; // nothing ore to find
if (options?.uniqueReplicators) {
if (
options.uniqueReplicators.size === leaders.size ||
options.uniqueReplicators.size === uniqueVisited.size
) {
break; // nothing more to find
}
}

if (options?.onlyIntersecting || matured > i) {
Expand All @@ -1639,6 +1646,7 @@ export const getSamples = async <R extends "u32" | "u64">(
roleAge,
peers,
(rect, m) => {
uniqueVisited.add(rect.hash);
const prev = leaders.get(rect.hash);
if (m) {
if (!prev) {
Expand Down
1 change: 0 additions & 1 deletion packages/utils/indexer/sqlite3/src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ export class SQLLiteIndex<T extends Record<string, any>>

/* console.log("----------------------")
console.log(sqlFetch); */

const allResults = await planningScope.perform(async () => {
const allResults: Record<string, any>[] = await stmt.all([
...bindable,
Expand Down

0 comments on commit 8987494

Please sign in to comment.