Merge branch 'main' into don't-show-culled-shapes

don't-show-culled-shapes
Steve Ruiz 2024-04-09 14:08:50 +01:00
commit 2dda76ead3
4 zmienionych plików z 35 dodań i 6 usunięć

Wyświetl plik

@ -4656,11 +4656,9 @@ export class Editor extends EventEmitter<TLEventMap> {
*
* @public
*/
@computed getCurrentPageRenderingShapesSorted(): TLShape[] {
return this.getUnorderedRenderingShapes(true)
.filter(({ id }) => !this.isShapeCulled(id))
.sort((a, b) => a.index - b.index)
.map(({ shape }) => shape)
@computed
getCurrentPageRenderingShapesSorted(): TLShape[] {
return this.getCurrentPageShapesSorted().filter((shape) => !this.isShapeCulled(shape))
}
/**

Wyświetl plik

@ -176,6 +176,9 @@ export function mapObjectMapValues<Key extends string, ValueBefore, ValueAfter>(
[K in Key]: ValueAfter;
};
// @internal (undocumented)
export function measureAverageDuration(_target: any, propertyKey: string, descriptor: PropertyDescriptor): PropertyDescriptor;
// @internal (undocumented)
export function measureCbDuration(name: string, cb: () => any): any;

Wyświetl plik

@ -36,7 +36,7 @@ export {
objectMapKeys,
objectMapValues,
} from './lib/object'
export { measureCbDuration, measureDuration } from './lib/perf'
export { measureAverageDuration, measureCbDuration, measureDuration } from './lib/perf'
export { PngHelpers } from './lib/png'
export { type IndexKey } from './lib/reordering/IndexKey'
export {

Wyświetl plik

@ -20,3 +20,31 @@ export function measureDuration(_target: any, propertyKey: string, descriptor: P
}
return descriptor
}
const averages = new Map<any, { total: number; count: number }>()
/** @internal */
export function measureAverageDuration(
_target: any,
propertyKey: string,
descriptor: PropertyDescriptor
) {
const originalMethod = descriptor.value
descriptor.value = function (...args: any[]) {
const start = performance.now()
const result = originalMethod.apply(this, args)
const end = performance.now()
const value = averages.get(descriptor.value)!
const length = end - start
const total = value.total + length
const count = value.count + 1
averages.set(descriptor.value, { total, count })
// eslint-disable-next-line no-console
console.log(
`${propertyKey} took ${(end - start).toFixed(2)}ms | average ${(total / count).toFixed(2)}ms`
)
return result
}
averages.set(descriptor.value, { total: 0, count: 0 })
return descriptor
}