Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as opaque submodule gitlinks on GitHub) into fully-tracked first-party content. AITM now merges its 7 vendored repos as first-party engines: - memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts - git: vendored C git (bundled binary) + gitnexus (in-process code intelligence) - agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess) Includes the full session's product build: Gitgram web/mobile/backend features, AITM website/CLI/MCP, the unified memory layer, engine build tooling (scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md), and extensive test suites. Build artifacts, node_modules, external/, and gemini-cli are gitignored. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
103 lines
2.4 KiB
TypeScript
103 lines
2.4 KiB
TypeScript
// Performance optimization utilities
|
|
import React from 'react';
|
|
|
|
// Lazy load component
|
|
export function lazyLoad<T extends React.ComponentType<any>>(
|
|
importFunc: () => Promise<{ default: T }>
|
|
): React.LazyExoticComponent<T> {
|
|
return React.lazy(importFunc);
|
|
}
|
|
|
|
// Debounce function for search/input
|
|
export function debounce<T extends (...args: any[]) => any>(
|
|
func: T,
|
|
wait: number
|
|
): (...args: Parameters<T>) => void {
|
|
let timeout: NodeJS.Timeout | null = null;
|
|
|
|
return function executedFunction(...args: Parameters<T>) {
|
|
const later = () => {
|
|
timeout = null;
|
|
func(...args);
|
|
};
|
|
|
|
if (timeout) {
|
|
clearTimeout(timeout);
|
|
}
|
|
timeout = setTimeout(later, wait);
|
|
};
|
|
}
|
|
|
|
// Throttle function for scroll events
|
|
export function throttle<T extends (...args: any[]) => any>(
|
|
func: T,
|
|
limit: number
|
|
): (...args: Parameters<T>) => void {
|
|
let inThrottle: boolean;
|
|
|
|
return function executedFunction(...args: Parameters<T>) {
|
|
if (!inThrottle) {
|
|
func(...args);
|
|
inThrottle = true;
|
|
setTimeout(() => (inThrottle = false), limit);
|
|
}
|
|
};
|
|
}
|
|
|
|
// Memoize expensive computations
|
|
export function memoize<Args extends any[], Return>(
|
|
fn: (...args: Args) => Return
|
|
): (...args: Args) => Return {
|
|
const cache = new Map<string, Return>();
|
|
|
|
return (...args: Args): Return => {
|
|
const key = JSON.stringify(args);
|
|
|
|
if (cache.has(key)) {
|
|
return cache.get(key)!;
|
|
}
|
|
|
|
const result = fn(...args);
|
|
cache.set(key, result);
|
|
return result;
|
|
};
|
|
}
|
|
|
|
// Image preloader
|
|
export function preloadImages(urls: string[]): Promise<void[]> {
|
|
return Promise.all(
|
|
urls.map(
|
|
(url) =>
|
|
new Promise<void>((resolve, reject) => {
|
|
const img = new Image();
|
|
img.onload = () => resolve();
|
|
img.onerror = reject;
|
|
img.src = url;
|
|
})
|
|
)
|
|
);
|
|
}
|
|
|
|
// Batch API calls
|
|
export function batchRequests<T>(
|
|
requests: (() => Promise<T>)[],
|
|
batchSize: number = 5
|
|
): Promise<T[]> {
|
|
const results: T[] = [];
|
|
|
|
const processBatch = async (batch: (() => Promise<T>)[]) => {
|
|
const batchResults = await Promise.all(batch.map((req) => req()));
|
|
results.push(...batchResults);
|
|
};
|
|
|
|
const processAll = async () => {
|
|
for (let i = 0; i < requests.length; i += batchSize) {
|
|
const batch = requests.slice(i, i + batchSize);
|
|
await processBatch(batch);
|
|
}
|
|
};
|
|
|
|
return processAll().then(() => results);
|
|
}
|
|
|