11import type { ChangeEvent } from "react" ;
2- import { Fragment , memo , useMemo , useRef , useState } from "react" ;
2+ import {
3+ Fragment ,
4+ memo ,
5+ useDeferredValue ,
6+ useMemo ,
7+ useRef ,
8+ useState ,
9+ } from "react" ;
310import type {
411 SetPerformanceComparisonQueries ,
512 ToComparePerformanceViewMessage ,
@@ -13,6 +20,7 @@ import { formatDecimal } from "../../common/number";
1320import { styled } from "styled-components" ;
1421import { Codicon , ViewTitle , WarningBox } from "../common" ;
1522import { abbreviateRANames , abbreviateRASteps } from "./RAPrettyPrinter" ;
23+ import { Renaming , RenamingInput } from "./RenamingInput" ;
1624
1725const enum AbsentReason {
1826 NotSeen = "NotSeen" ,
@@ -381,9 +389,13 @@ function addOptionals(a: Optional<number>, b: Optional<number>) {
381389/**
382390 * Returns a "fingerprint" from the given name, which is used to group together similar names.
383391 */
384- export function getNameFingerprint ( name : string ) {
385- // For now just remove the hash from the name. We identify this as a '#' followed by exactly 8 hexadecimal characters.
386- return name . replace ( / # [ 0 - 9 a - f ] { 8 } (? ! [ 0 - 9 a - f ] ) / g, "" ) ;
392+ export function getNameFingerprint ( name : string , renamings : Renaming [ ] ) {
393+ for ( const { patternRegexp, replacement } of renamings ) {
394+ if ( patternRegexp != null ) {
395+ name = name . replace ( patternRegexp , replacement ) ;
396+ }
397+ }
398+ return name ;
387399}
388400
389401function Chevron ( { expanded } : { expanded : boolean } ) {
@@ -486,10 +498,17 @@ function ComparePerformanceWithData(props: {
486498 return { totalBefore, totalAfter, totalDiff } ;
487499 } , [ rows , metric ] ) ;
488500
501+ const [ renamings , setRenamings ] = useState < Renaming [ ] > ( ( ) => [
502+ new Renaming ( "#[0-9a-f]{8}(?![0-9a-f])" , "#" ) ,
503+ ] ) ;
504+
505+ // Use deferred value to avoid expensive re-rendering for every keypress in the renaming editor
506+ const deferredRenamings = useDeferredValue ( renamings ) ;
507+
489508 const rowGroups = useMemo ( ( ) => {
490509 const groupedRows = new Map < string , Row [ ] > ( ) ;
491510 for ( const row of rows ) {
492- const fingerprint = getNameFingerprint ( row . name ) ;
511+ const fingerprint = getNameFingerprint ( row . name , deferredRenamings ) ;
493512 const rows = groupedRows . get ( fingerprint ) ;
494513 if ( rows ) {
495514 rows . push ( row ) ;
@@ -515,7 +534,7 @@ function ComparePerformanceWithData(props: {
515534 } satisfies RowGroup ;
516535 } )
517536 . sort ( getSortOrder ( sortOrder ) ) ;
518- } , [ rows , metric , sortOrder ] ) ;
537+ } , [ rows , metric , sortOrder , deferredRenamings ] ) ;
519538
520539 const rowGroupNames = useMemo (
521540 ( ) => abbreviateRANames ( rowGroups . map ( ( group ) => group . name ) ) ,
@@ -544,6 +563,7 @@ function ComparePerformanceWithData(props: {
544563 </ label >
545564 </ WarningBox >
546565 ) }
566+ < RenamingInput renamings = { renamings } setRenamings = { setRenamings } />
547567 Compare{ " " }
548568 < Dropdown
549569 onChange = { ( e : ChangeEvent < HTMLSelectElement > ) =>
0 commit comments