Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SQL Lab] Improve result table rendering performance #7690

Closed
wants to merge 1 commit into from

Conversation

etr2460
Copy link
Member

@etr2460 etr2460 commented Jun 11, 2019

CATEGORY

Choose one

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

When rendering the FilterableTable component we were rendering and measuring the width of every cell to determine the width of each column. For tables with many columns or columns with large amounts of content, this would hang the page for seconds at a time:
Screen Shot 2019-06-11 at 9 55 09 AM

This fix changes the font for the FilterableTable to monospaced so that we can calculate the max width of a column without rendering the each cell. This resulted in a 665x improvement in perf for the function (>3 s down to 4.8 ms in some nasty edge cases)
Screen Shot 2019-06-11 at 9 53 39 AM

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before:
slow query

After:
faster query

TEST PLAN

Ensure the column widths still fit all the content. Pass CI

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

REVIEWERS

@graceguo-supercat @soboko @mistercrunch @john-bodley

Copy link
Member

@betodealmeida betodealmeida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome, I think it will greatly improve with the wide tables we've been previewing. I have just a comment on the font, we should have a designer chime in, since the new font is much harder to read IMHO.

@@ -43,6 +43,11 @@
border-right: 1px solid #ccc;
align-self: center;
padding: 12px;
font-family: monospace;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could have a more specific font here first (falling back to monospace if not available), so the results look better? At least in the screenshot you posted the monospaced font seems harder to read than before.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested with 'Roboto Mono', monospace and it looks somewhat better IMHO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd need to include roboto mono with the website then, not sure if it's worth adding a dependency there on a font. Let's see what someone more design minded thinks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily, it would fall back to monospace if Roboto Mono is not installed.

GitHub uses SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace;, eg.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different fonts would have different character widths, which would make this even harder to implement though..

return getTextDimension({ text, style: { font } }).width;
}

const CHARACTER_WIDTH = 8;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etr2460, can you test your modifications with Unicode data? You can try a query like this:

SELECT 'アイウ1234', 'QRS12', '台北1234';

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested
Screen Shot 2019-06-12 at 5 19 14 PM

Copy link
Member

@betodealmeida betodealmeida Jun 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern is that strings with the same number of characters may have different widths when rendering in monospace. For example, these 3 strings all have 3 characters:

'アイウ',
'123',
'QRS'

Note that they're rendered with different widths, since some characters are half-width and others are double.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>>> a = ['123', 'アイウ', 'QRS']
>>> [len(i) for i in a]
[3, 3, 3]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see your point here. It is possible to get the columns to overflow with enough double wide characters, but in that case you can still hover over the column to see the full results, or copy/paste to the same effect.

@betodealmeida
Copy link
Member

@etr2460 I'm doing some tests trying to optimize getTextDimension to avoid modifying the DOM, reusing the nodes instead of creating them from scratch all the time.

@etr2460
Copy link
Member Author

etr2460 commented Jun 13, 2019

@etr2460 I'm doing some tests trying to optimize getTextDimension to avoid modifying the DOM, reusing the nodes instead of creating them from scratch all the time.

That should definitely help performance too! I think separate of the performance question, we should consider if monospace is the right direction to go for the query results. For some types of data, I think it's actually easier to read in monospace, but it probably depends on people's preference

@etr2460
Copy link
Member Author

etr2460 commented Jun 13, 2019

Design change: @elibrumbaugh do you wanna take a look? Context is above

Before:
Screen Shot 2019-06-12 at 5 21 25 PM

After:
Screen Shot 2019-06-12 at 5 20 58 PM

@elibrumbaugh
Copy link

@etr2460 Thanks for the tag. I find the monospace easier to read and it sounds like a big win for performance. My biggest concern is how "spaced" out the letters are now. In design we call this tracking or more recently letter-spacing. Check out this bit about legibility.

  1. I think you should try to reduce the amount of spacing.
  2. Run it past SQL Lab users. You would be surprised how sensitive people can be about this kind of typographic change.

Keep me posted!

@elibrumbaugh
Copy link

I apologize Erik, I made a mistake. Monospace of course is a fixed width.

I wonder if it's worth the extra space because of the advantage of spacing out compressed syntax per the link I shared in this comment.

@etr2460
Copy link
Member Author

etr2460 commented Jun 13, 2019

@elibrumbaugh spacing out JSON is definitely a perk for using a monospace font here. I'll try to find some folks who use sql lab on a daily basis for feedback!

@betodealmeida
Copy link
Member

Personally I prefer the old style, but I've learned to trust designers in cases like this. If @elibrumbaugh says it's better I'm happy to go with it. :)

@elibrumbaugh
Copy link

Thanks Beto 🙏We'll def confirm with users first!

@mistercrunch
Copy link
Member

mistercrunch commented Jun 14, 2019

Side note outside the scope of this PR: I thought before that it could be good to limit/collapse wide columns to say 100 chars by default and allow users to expand it. Maybe a right caret in the column header that widens the column to its full extend?

For json specifically, when detected we could also allow a modal on click that would auto-json-format.

Copy link
Member Author

@etr2460 etr2460 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@betodealmeida let me know what sorts of perf improvements you get by changing the measurement component. if that fixes it enough, then we can make the table monospaced with better looking fonts, otherwise this is probably fine to merge as is. I spoke with some other users of SQL Lab and they all were ok with the change

@@ -43,6 +43,11 @@
border-right: 1px solid #ccc;
align-self: center;
padding: 12px;
font-family: monospace;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different fonts would have different character widths, which would make this even harder to implement though..

return getTextDimension({ text, style: { font } }).width;
}

const CHARACTER_WIDTH = 8;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see your point here. It is possible to get the columns to overflow with enough double wide characters, but in that case you can still hover over the column to see the full results, or copy/paste to the same effect.

@etr2460
Copy link
Member Author

etr2460 commented Aug 8, 2019

Superseded by #8011

@etr2460 etr2460 closed this Aug 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants