Skip to content

Commit

Permalink
Wire up some more
Browse files Browse the repository at this point in the history
  • Loading branch information
oleavr committed Sep 26, 2024
1 parent 910a52d commit a196a4b
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion apps/tracer/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export function useModel() {
const [addingTargets, setAddingTargets] = useState(false);
const [stagedItems, setStagedItems] = useState<StagedItem[]>([]);

const cachedSymbolsRef = useRef(new Map<string, string>());

const request = useCallback(<T extends RequestType>(type: T, payload: RequestPayload[T]): Promise<ResponsePayload[T]> => {
const rpcState = rpcStateRef.current;
const id = rpcState.nextRequestId++;
Expand Down Expand Up @@ -169,7 +171,26 @@ export function useModel() {
}, [request]);

const symbolicate = useCallback(async (addresses: string[]): Promise<string[]> => {
return (await request("symbols:resolve-addresses", { addresses })).names;
const cache = cachedSymbolsRef.current;

const result = addresses.map(address => cache.get(address) ?? null);

const missingIndices = result.reduce((acc, element, i) => {
if (element === null) {
acc.push(i);
}
return acc;
}, [] as number[]);
if (missingIndices.length !== 0) {
const missingAddresses = missingIndices.map(i => addresses[i]);
const { names } = await request("symbols:resolve-addresses", { addresses: missingAddresses });
names.forEach((name, i) => {
cache.set(missingAddresses[i], name);
result[missingIndices[i]] = name;
});
}

return result as string[];
}, [request]);

useEffect(() => {
Expand Down

0 comments on commit a196a4b

Please sign in to comment.