Skip to content

Commit

Permalink
don't throttle trace update
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Jun 21, 2024
1 parent 2f7ee91 commit ea58463
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 40 deletions.
37 changes: 0 additions & 37 deletions packages/core/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,43 +63,6 @@ export function assert(
}
}

export function throttle(handler: () => void, delay: number): () => void {
let enableCall = true
return function () {
if (!enableCall) return
enableCall = false
handler()
setTimeout(() => (enableCall = true), delay)
}
}

export function arrayShuffle<T>(a: T[]): T[] {
for (let i = a.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1))
;[a[i], a[j]] = [a[j], a[i]]
}
return a
}

export function range(end: number): number[] {
return Array(end)
.fill(0)
.map((_, i) => i)
}

export function toggleBit(data: Uint8Array, bitindex: number) {
data[bitindex >> 3] ^= 1 << (bitindex & 7)
}

export function getBit(data: Uint8Array, bitindex: number) {
return !!(data[bitindex >> 3] & (1 << (bitindex & 7)))
}

export function setBit(data: Uint8Array, bitindex: number, on: boolean) {
if (on) data[bitindex >> 3] |= 1 << (bitindex & 7)
else data[bitindex >> 3] &= ~(1 << (bitindex & 7))
}

export function concatBuffers(...chunks: Uint8Array[]) {
let sz = 0
for (const ch of chunks) sz += ch.length
Expand Down
4 changes: 1 addition & 3 deletions packages/vscode/src/tracetree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as vscode from "vscode"
import { ExtensionState } from "./state"
import {
CHANGE,
throttle,
TRACE_NODE_PREFIX,
TraceNode,
} from "genaiscript-core"
Expand All @@ -16,8 +15,7 @@ function unmarkdown(text: string) {

class TraceTreeDataProvider implements vscode.TreeDataProvider<TraceNode> {
constructor(readonly state: ExtensionState) {
const throttledRefresh = throttle(this.refresh.bind(this), 1000)
this.state.addEventListener(CHANGE, throttledRefresh)
this.state.addEventListener(CHANGE, () => this.refresh())
}

getTreeItem(
Expand Down

0 comments on commit ea58463

Please sign in to comment.