perf: virtualize LUT directory rows as well as thumbnails for large libraries

这个提交包含在:
mac 于 2026-11-01 11:09:41 +08:00 提交
1 父节点 87baa785fd
当前提交 838037a7e0
4 个文件已更改
+45 -21

没有与搜索条件相匹配的文件

+9 -2
查看文件
@@ -69,12 +69,18 @@ int main(int argc,const char *argv[]) {@autoreleasepool {
// Real browser objects, never shown; its grid should represent thousands of
// files with only visible/overscan buttons, including after a distant scroll.
NSURL *catalog=[destination URLByAppendingPathComponent:@"Catalog" isDirectory:YES];[fm createDirectoryAtURL:catalog withIntermediateDirectories:NO attributes:nil error:&error];
BOOL catalogOK=YES;for(NSUInteger i=0;i<3000;i++){NSString *path=[catalog.path stringByAppendingPathComponent:[NSString stringWithFormat:@"Catalog-%04lu.cube",(unsigned long)i]];if(link(anchor.path.fileSystemRepresentation,path.fileSystemRepresentation)!=0){catalogOK=NO;break;}}require(catalogOK,@"3000 catalog fixtures created");
BOOL catalogOK=YES;for(NSUInteger i=0;i<3000;i++){
NSString *folder=[destination.path stringByAppendingPathComponent:[NSString stringWithFormat:@"Folder-%04lu",(unsigned long)i]];
if(![fm createDirectoryAtPath:folder withIntermediateDirectories:NO attributes:nil error:&error]){catalogOK=NO;break;}
NSString *path=[folder stringByAppendingPathComponent:[NSString stringWithFormat:@"Catalog-%04lu.cube",(unsigned long)i]];
if(link(anchor.path.fileSystemRepresentation,path.fileSystemRepresentation)!=0){catalogOK=NO;break;}
}require(catalogOK,@"3000 catalog files in independent folders created");
[NSApplication sharedApplication];[NSApp setActivationPolicy:NSApplicationActivationPolicyProhibited];
NSMutableArray *selected=[NSMutableArray array];
DYLUTBrowser *browser=[[DYLUTBrowser alloc]initWithLibrary:library preview:nil selectedPath:nil palette:@{} selection:^(NSString *path){[selected addObject:path?:@""];}];
pump(^{return [browser valueForKey:@"libraryTask"]==nil;});
NSUInteger visible=[[browser valueForKey:@"visibleEntries"]count],tileCount=[[browser valueForKey:@"tiles"]count];
require([[browser valueForKey:@"folderPaths"]count]>3000&&[[browser valueForKey:@"folderButtons"]count]<30,@"large directory list creates only visible folder controls");
require(visible==3025&&tileCount>0&&tileCount<200,@"large catalog creates only visible thumbnail controls");
NSScrollView *scroll=[browser valueForKey:@"gridScroll"];[scroll.contentView scrollToPoint:NSMakePoint(0,scroll.documentView.frame.size.height-scroll.contentSize.height)];[browser layoutBrowser];
require([[browser valueForKey:@"tiles"]count]<200,@"scrolling keeps thumbnail view count bounded");
@@ -85,9 +91,10 @@ int main(int argc,const char *argv[]) {@autoreleasepool {
require(selected.count==1&&[selected.lastObject isEqual:keys[1]],@"rapid selection applies only the latest LUT");
[browser thumbnailClicked:tiles[keys[0]]];[browser clearSelection:nil];pump(^{return [browser valueForKey:@"selectionTask"]==nil;});
require([selected.lastObject isEqual:@""],@"clear selection supersedes pending LUT application");
NSUInteger folderViews=[[browser valueForKey:@"folderButtons"]count];
[browser importSelectedURLs:@[source]];[browser close];done=NO;[library reloadAsync:^(NSError *failure){require(!failure,@"scan after browser close completes");done=YES;}];pump(^{return done;});
require(library.entries.count==3025,@"closing during import cancels without changing existing library");
[browser release];report[@"largeCatalogEntries"]=@(visible);report[@"initialLiveThumbnailViews"]=@(tileCount);report[@"pass"]=@YES;
[browser release];report[@"largeCatalogEntries"]=@(visible);report[@"initialLiveThumbnailViews"]=@(tileCount);report[@"initialLiveFolderViews"]=@(folderViews);report[@"pass"]=@YES;
#else
report[@"mode"]=@"baseline synchronous import";
#endif
+10 -5
查看文件
@@ -134,7 +134,7 @@
},
"background": {
"sourceBytes": 197731344,
"mainHeartbeatMaxGapMS": 6.287041702307761,
"mainHeartbeatMaxGapMS": 6.251125014387071,
"bulkFiles": 24,
"checks": [
{
@@ -310,13 +310,17 @@
"pass": true
},
{
"name": "3000 catalog fixtures created",
"name": "3000 catalog files in independent folders created",
"pass": true
},
{
"name": "background operation completes within timeout",
"pass": true
},
{
"name": "large directory list creates only visible folder controls",
"pass": true
},
{
"name": "large catalog creates only visible thumbnail controls",
"pass": true
@@ -359,13 +363,14 @@
}
],
"initialLiveThumbnailViews": 45,
"snapshotsReadDuringImport": 1493,
"snapshotsReadDuringImport": 1486,
"mainHeartbeatTicks": 1486,
"scope": "Synthetic 24 x 65-cube import with real main-run-loop heartbeat and snapshot reads; headless browser cancellation, latest selection and 3,025-entry virtualization. No user library or visible test app.",
"mainHeartbeatTicks": 1493,
"pass": true,
"largeCatalogEntries": 3025,
"cubeDimension": 65,
"importSeconds": 7.432438375079073
"initialLiveFolderViews": 15,
"importSeconds": 7.3989348750328645
},
"coreLibraryChecks": 92,
"coreLibraryPassed": true,
+24 -13
查看文件
@@ -116,7 +116,7 @@ static NSString *const DYBrowserFolderPreference=@"com.dayu.color.lookLUTPreview
NSSlider *_sizeSlider;
NSMutableArray *_folderButtons;
NSMutableDictionary *_tiles;
NSArray *_visibleEntries;
NSArray *_visibleEntries,*_folderPaths;
NSMutableSet *_queuedPaths;
NSCache *_thumbnailCache;
dispatch_queue_t _previewQueue;
@@ -160,6 +160,8 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
_gridScroll=[[NSScrollView alloc]initWithFrame:NSZeroRect];_gridScroll.hasVerticalScroller=YES;_gridScroll.autohidesScrollers=YES;_gridScroll.borderType=NSNoBorder;_gridScroll.drawsBackground=NO;_gridScroll.accessibilityLabel=@"LUT 缩略图网格";
_folderDocument=[[DYBrowserCanvas alloc]initWithFrame:NSZeroRect];_folderDocument.fillKey=@"card";_folderDocument.palette=_palette;_folderDocument.accessibilityLabel=@"LUT 文件夹";_folderScroll.documentView=_folderDocument;
_gridDocument=[[DYBrowserCanvas alloc]initWithFrame:NSZeroRect];_gridDocument.palette=_palette;_gridDocument.accessibilityLabel=@"LUT 缩略图";_gridScroll.documentView=_gridDocument;
_folderScroll.contentView.postsBoundsChangedNotifications=YES;
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(folderScrolled:) name:NSViewBoundsDidChangeNotification object:_folderScroll.contentView];
_gridScroll.contentView.postsBoundsChangedNotifications=YES;
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(gridScrolled:) name:NSViewBoundsDidChangeNotification object:_gridScroll.contentView];
for(NSView *view in @[_titleLabel,_countLabel,_statusLabel,_sizeLabel,_search,_importFiles,_importFolder,_reveal,_refresh,_none,_done,_sizeSlider,_folderScroll,_gridScroll])[_root addSubview:view];
@@ -180,7 +182,7 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
[_root release];[_folderDocument release];[_gridDocument release];[_folderScroll release];[_gridScroll release];
[_titleLabel release];[_countLabel release];[_statusLabel release];[_sizeLabel release];[_emptyLabel release];[_search release];
[_importFiles release];[_importFolder release];[_reveal release];[_refresh release];[_none release];[_done release];[_sizeSlider release];
[_folderButtons release];[_tiles release];[_visibleEntries release];[_queuedPaths release];[_thumbnailCache release];
[_folderButtons release];[_folderPaths release];[_tiles release];[_visibleEntries release];[_queuedPaths release];[_thumbnailCache release];
dispatch_release(_previewQueue);[super dealloc];
}
- (void)showRelativeToView:(NSView *)view{
@@ -239,9 +241,9 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
_sizeLabel.frame=NSMakeRect(left+101,h-39,74,18);_sizeSlider.frame=NSMakeRect(left+173,h-41,MAX(70,MIN(150,w-left-420)),20);
_done.frame=NSMakeRect(w-98,h-44,78,27);
CGFloat statusX=NSMaxX(_sizeSlider.frame)+14;_statusLabel.frame=NSMakeRect(statusX,h-39,MAX(0,w-statusX-112),18);
CGFloat fy=4,fw=MAX(100,_folderScroll.contentSize.width);
for(DYBrowserFolderButton *button in _folderButtons){button.frame=NSMakeRect(4,fy,fw-8,33);fy+=35;}
_folderDocument.frame=NSMakeRect(0,0,fw,MAX(fy,_folderScroll.contentSize.height));
CGFloat fw=MAX(100,_folderScroll.contentSize.width);
_folderDocument.frame=NSMakeRect(0,0,fw,MAX(_folderPaths.count*35+4,_folderScroll.contentSize.height));
[self updateVisibleFolders];
CGFloat available=MAX(80,_gridScroll.contentSize.width),tileWidth=_sizeSlider.doubleValue,gap=10;
NSInteger columns=MAX(1,(NSInteger)floor((available+gap)/(tileWidth+gap)));tileWidth=MIN(tileWidth,(available-gap*(columns-1)-14)/columns);tileWidth=MAX(70,tileWidth);
_columns=columns;_tileWidth=tileWidth;_tileHeight=ceil(tileWidth*9/16)+24;
@@ -290,15 +292,24 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
}
- (void)setStatus:(NSString *)status{_statusLabel.stringValue=status?:@"";_statusLabel.toolTip=status;}
- (void)rebuildFolders{
for(NSView *view in _folderButtons)[view removeFromSuperview];[_folderButtons removeAllObjects];
NSMutableArray *paths=[NSMutableArray arrayWithObject:@"*"];
for(NSString *folder in _library.folders){NSString *top=folder.length?[folder componentsSeparatedByString:@"/"].firstObject:@"";if(![paths containsObject:top])[paths addObject:top];}
if(![paths containsObject:_folder]){[_folder release];_folder=[@"*" copy];}
for(NSString *path in paths){
DYBrowserFolderButton *button=[[[DYBrowserFolderButton alloc]initWithFrame:NSZeroRect]autorelease];button.bordered=NO;button.target=self;button.action=@selector(folderClicked:);button.identifier=path;
button.title=[path isEqualToString:@"*"]?@"全部 LUT":path.length?[@"▸ " stringByAppendingString:path]:@"未分类";button.toolTip=path.length?path:_library.rootURL.path;button.palette=_palette;button.chosen=[path isEqualToString:_folder];button.accessibilityLabel=[@"LUT 文件夹:" stringByAppendingString:button.title];
[_folderDocument addSubview:button];[_folderButtons addObject:button];
NSMutableArray *paths=[NSMutableArray arrayWithObject:@"*"];NSMutableSet *seen=[NSMutableSet setWithObject:@"*"];
for(NSString *folder in _library.folders){NSString *top=folder.length?[folder componentsSeparatedByString:@"/"].firstObject:@"";if(![seen containsObject:top]){[paths addObject:top];[seen addObject:top];}}
if(![seen containsObject:_folder]){[_folder release];_folder=[@"*" copy];}
[_folderPaths release];_folderPaths=[paths copy];[self updateVisibleFolders];
}
- (void)folderScrolled:(NSNotification *)notification{if(!_layingOut)[self updateVisibleFolders];}
- (void)updateVisibleFolders {
if(_closed)return;NSRect visible=NSInsetRect(_folderScroll.contentView.bounds,0,-35);
NSUInteger first=(NSUInteger)MAX(0,floor(NSMinY(visible)/35)),end=MIN(_folderPaths.count,(NSUInteger)MAX(0,ceil(NSMaxY(visible)/35)+1));
NSMutableDictionary *existing=[NSMutableDictionary dictionary];for(NSButton *button in _folderButtons)existing[button.identifier]=button;
NSMutableArray *buttons=[NSMutableArray array];
for(NSUInteger i=first;i<end;i++){
NSString *path=_folderPaths[i];DYBrowserFolderButton *button=existing[path];
if(!button){button=[[[DYBrowserFolderButton alloc]initWithFrame:NSZeroRect]autorelease];button.bordered=NO;button.target=self;button.action=@selector(folderClicked:);button.identifier=path;
button.title=[path isEqualToString:@"*"]?@"全部 LUT":path.length?[@"▸ " stringByAppendingString:path]:@"未分类";button.toolTip=path.length?path:_library.rootURL.path;button.palette=_palette;button.accessibilityLabel=[@"LUT 文件夹:" stringByAppendingString:button.title];[_folderDocument addSubview:button];}
button.chosen=[path isEqualToString:_folder];button.frame=NSMakeRect(4,4+i*35,MAX(92,_folderScroll.contentSize.width-8),33);[button setNeedsDisplay:YES];[buttons addObject:button];
}
for(NSButton *button in _folderButtons)if(![buttons containsObject:button])[button removeFromSuperview];[_folderButtons setArray:buttons];
}
- (void)pollLibraryProgress:(NSTimer *)timer {
if(_libraryTask)[self setStatus:_libraryTask.localizedDescription];
+2 -1
查看文件
@@ -316,7 +316,8 @@ static BOOL DYLUTEnsureDirectory(NSURL *directory,NSURL *root,NSError **error) {
if(scanError){if(error)*error=scanError;return NO;}
[entries sortUsingComparator:^NSComparisonResult(NSDictionary *a,NSDictionary *b){return [a[@"relativePath"]localizedStandardCompare:b[@"relativePath"]];}];
if(DYLUTCancelled(progress,error))return NO;
@synchronized(self){[_entries release];_entries=[entries copy];[_folders release];_folders=[[folders.allObjects sortedArrayUsingSelector:@selector(localizedStandardCompare:)]copy];}return YES;
NSArray *sortedFolders=[folders.allObjects sortedArrayUsingSelector:@selector(localizedStandardCompare:)];
@synchronized(self){[_entries release];_entries=[entries copy];[_folders release];_folders=[sortedFolders copy];}return YES;
}}
- (NSArray *)importURLs:(NSArray<NSURL *> *)urls error:(NSError **)error {return [self importURLs:urls progress:nil error:error];}
- (NSArray *)importURLs:(NSArray<NSURL *> *)urls progress:(NSProgress *)progress error:(NSError **)error {@synchronized(_fileLock){