Skip to content
Snippets Groups Projects
Commit 868d531b authored by George Nachman's avatar George Nachman
Browse files

Improve performance of opening a window with the Profiles tool present when...

Improve performance of opening a window with the Profiles tool present when there are many profiles. We spent a long time calculting row heights. It's still slow because every row needs to be queried, but it's a lot faster than it used to be. Issue 6322
parent 02e75fef
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -71,6 +71,7 @@ extern NSString *const kProfileWasDeletedNotification;
@property(nonatomic, readonly) NSString *selectedGuid;
 
- (instancetype)initWithFrame:(NSRect)frameRect model:(ProfileModel*)dataSource;
- (instancetype)initWithFrame:(NSRect)frameRect model:(ProfileModel*)dataSource font:(NSFont *)font;
- (ProfileModelWrapper*)dataSource;
- (void)setUnderlyingDatasource:(ProfileModel*)dataSource;
- (void)focusSearchField;
Loading
Loading
Loading
Loading
@@ -66,14 +66,23 @@ const CGFloat kDefaultTagsWidth = 80;
NSSplitView *splitView_;
CGFloat lastTagsWidth_;
NSMutableDictionary<NSNumber *, NSNumber *> *_savedHeights;
// Cached row height info
BOOL _haveHeights;
CGFloat _heightWithTags;
CGFloat _heightWithoutTags;
}
 
- (instancetype)initWithFrame:(NSRect)frameRect {
return [self initWithFrame:frameRect model:[ProfileModel sharedInstance]];
}
 
// This is the designated initializer.
- (instancetype)initWithFrame:(NSRect)frameRect model:(ProfileModel*)dataSource {
return [self initWithFrame:frameRect model:dataSource font:nil];
}
- (instancetype)initWithFrame:(NSRect)frameRect model:(ProfileModel *)dataSource font:(NSFont *)font {
self = [super initWithFrame:frameRect];
if (self) {
_savedHeights = [[NSMutableDictionary alloc] init];
Loading
Loading
@@ -148,8 +157,6 @@ const CGFloat kDefaultTagsWidth = 80;
[scrollView_ setDocumentView:tableView_];
[scrollView_ setBorderType:NSBezelBorder];
 
[tableView_ setDelegate:self];
[tableView_ setDataSource:self];
selectedGuids_ = [[NSMutableSet alloc] init];
 
[tableView_ setDoubleAction:@selector(onDoubleClick:)];
Loading
Loading
@@ -179,6 +186,12 @@ const CGFloat kDefaultTagsWidth = 80;
tagsView_.delegate = self;
[splitView_ addSubview:tagsView_];
[splitView_ addSubview:scrollView_];
if (font) {
[self setFont:font];
}
[tableView_ setDataSource:self];
[tableView_ setDelegate:self];
}
return self;
}
Loading
Loading
@@ -474,14 +487,27 @@ const CGFloat kDefaultTagsWidth = 80;
[self reloadData];
}
 
- (CGFloat)heightOfRowWithTags:(BOOL)hasTags {
if (!_haveHeights) {
_heightWithTags = [[self attributedStringForName:@"M"
tags:@[ @"M" ]
selected:NO
isDefault:YES
filter:nil] heightForWidth:100];
_heightWithoutTags = [[self attributedStringForName:@"M"
tags:nil
selected:NO
isDefault:YES
filter:nil] heightForWidth:100];
_haveHeights = YES;
}
return hasTags ? _heightWithTags : _heightWithoutTags;
}
- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)rowIndex {
NSAttributedString *attributedString = [self tableView:tableView objectValueForTableColumn:tableColumn_ row:rowIndex];
// tableview is a mess. Add some points so it works. Who knows why.
Profile *profile = [dataSource_ profileAtIndex:rowIndex];
const BOOL hasTags = ([profile[KEY_TAGS] count] > 0);
CGFloat height = [attributedString heightForWidth:tableColumn_.width] + [self extraHeightWithTags:hasTags];
CGFloat height = [self heightOfRowWithTags:hasTags];
_savedHeights[@(rowIndex)] = @(height);
return height;
}
Loading
Loading
@@ -898,16 +924,18 @@ const CGFloat kDefaultTagsWidth = 80;
frame.size.height - kSearchWidgetHeight - margin_);
splitView_.frame = splitViewFrame;
 
NSMutableIndexSet *rowsWithHeightChange = [NSMutableIndexSet indexSet];
for (NSInteger i = 0; i < self.numberOfRows; i++) {
CGFloat savedHeight = [_savedHeights[@(i)] doubleValue];
CGFloat height = [self tableView:tableView_ heightOfRow:i];
if (round(height) != round(savedHeight)) {
[rowsWithHeightChange addIndex:i];
if (tableView_.delegate) {
NSMutableIndexSet *rowsWithHeightChange = [NSMutableIndexSet indexSet];
for (NSInteger i = 0; i < self.numberOfRows; i++) {
CGFloat savedHeight = [_savedHeights[@(i)] doubleValue];
CGFloat height = [self tableView:tableView_ heightOfRow:i];
if (round(height) != round(savedHeight)) {
[rowsWithHeightChange addIndex:i];
}
}
if (rowsWithHeightChange.count > 0) {
[tableView_ noteHeightOfRowsWithIndexesChanged:rowsWithHeightChange];
}
}
if (rowsWithHeightChange.count > 0) {
[tableView_ noteHeightOfRowsWithIndexesChanged:rowsWithHeightChange];
}
}
 
Loading
Loading
@@ -924,6 +952,7 @@ const CGFloat kDefaultTagsWidth = 80;
 
- (void)setFont:(NSFont *)theFont
{
_haveHeights = NO;
for (NSTableColumn *col in [tableView_ tableColumns]) {
[[col dataCell] setFont:theFont];
}
Loading
Loading
Loading
Loading
@@ -26,10 +26,11 @@ static const CGFloat kInnerMargin = 5;
- (instancetype)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
listView_ = [[ProfileListView alloc] initWithFrame:NSMakeRect(kMargin, 0, frame.size.width - kMargin * 2, frame.size.height - kPopupHeight - kVerticalMargin)];
listView_ = [[ProfileListView alloc] initWithFrame:NSMakeRect(kMargin, 0, frame.size.width - kMargin * 2, frame.size.height - kPopupHeight - kVerticalMargin)
model:[ProfileModel sharedInstance]
font:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
[listView_ setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[listView_ setDelegate:self];
[listView_ setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
[listView_ disableArrowHandler];
[listView_ allowMultipleSelections];
[listView_.tableView setHeaderView:nil];
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment