Skip to content

Comments

Truncate _source summary in doc table#9394

Closed
Bargs wants to merge 2 commits intoelastic:masterfrom
Bargs:truncateSource
Closed

Truncate _source summary in doc table#9394
Bargs wants to merge 2 commits intoelastic:masterfrom
Bargs:truncateSource

Conversation

@Bargs
Copy link
Contributor

@Bargs Bargs commented Dec 6, 2016

Previously when rendering the _source column in the doc table we
would inject the entire _source contents into the DOM and then
"truncate" it by setting a max height on the element in CSS. Despite
being hidden from view this content still had an impact on the browser's
layout calculations. Even for modestly sized documents (e.g. makelogs)
the impact was quite large (>200 ms). This commit actually truncates
the content to a maxiumum size based on number of characters in the
field names and values.

(the below tests were performed with this PR applied on top of #9326 to reduce the noise from the issues fixed by that PR)

Before
screen shot 2016-12-06 at 1 54 30 pm

After
screen shot 2016-12-06 at 1 56 25 pm

Previously when rendering the _source column in the doc table we
would inject the entire _source contents into the DOM and then
"truncate" it by setting a max height on the element in CSS. Despite
being hidden from view this content still had an impact on the browser's
layout calculations. Even for modestly sized documents (e.g. makelogs)
the impact was quite large (>200 ms). This commit actually truncates
the content to a maxiumum size based on number of characters in the
field names and values.
Copy link
Member

@weltenwort weltenwort left a comment

Choose a reason for hiding this comment

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

Oh my, the table_row code is a very special snowflake (not your new code, but the whole contraption). I guess we could gain a lot of performance by just rewriting that as a normal directive with a simple template. The way it is written now it stores a lot of state in the DOM and manipulates the DOM structure repeatedly (e.g. emptying the element and re-adding children) which usually does not perform well. I'd like to give that a try some day (if nobody else has done it by then).

Aside from that I am wondering whether this is a "breaking" change from the user's perspective. After all, you were able to select and copy+paste the whole cell content before even if it was truncated.

How did you come up with the magic number 500? The cell truncation height is configurable but this would just cut off the content after 500 characters even if the user set a large maximum height.

Anyway, this is a great place to start improving the performance 😄 thank you for investing the time 👍

sourceList.append(listPair);
sourceList.append(' ');
}
});
Copy link
Member

Choose a reason for hiding this comment

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

This still performs a lot of individual DOM manipulations. What about first calculating the number of elements to keep and then removing any additional children of sourceList in one operation (e.g. using the :gt(index) selector and .remove())?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since sourceList hasn't been injected into the document yet, is appending really an expensive operation? The browser won't need to calculate style, layout, etc until the template is compiled here, right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, you're correct. 😊 Still, since you're optimizing for performance just pushing individual items onto the collection might be costly. Probably depends on how this is implemented internally in jQuery/jqLite.

@Bargs
Copy link
Contributor Author

Bargs commented Dec 7, 2016

Yeah it's a bit of a rube goldberg setup :) I considered a larger rewrite but it didn't seem like the risk/reward was good enough at the moment.

I don't think we generally consider purely UI changes to be breaking changes, but it's a good point. What's your opinion @epixa?

500 just seemed like a good number for most normal screen sizes at regular font sizes. I'll make it configurable, it makes sense considering users can adjust the truncated height.

@lukasolson lukasolson removed their assignment Dec 8, 2016
@lukasolson lukasolson self-requested a review December 8, 2016 20:46
return text;
}

function truncateSourceSummary(sourceElement) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems to me it might make more sense to have this logic here. Then you don't have to check if the "discover-table-sourcefield" class exists, nor deal with the DOM. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about that, went back and forth a bit and I could still be convinced but here was my thinking:

The source formatter is a generic utility that could be used in lots of places, so while we want a truncated version in the doc table we might not want a truncated version everywhere the source formatter is used. Since it's the doc table that has specific requirements for the content, it's best suited to do the truncation.

But I just realized the current implementation won't work. Someone could theoretically specify a different field formatter for the _source field, and this logic would break because it expects a particular html structure.

I thought about defining a new content type, so in addition to text and html maybe we'd have something like html-summary that the doc table could request but I dunno, it feels a little hacky, html-summary isn't really a content type. Do you have any ideas? I'm not super familiar with the field formatter code

@Bargs
Copy link
Contributor Author

Bargs commented Dec 16, 2016

The more I think about this, the more I feel a change in design will be a better solution than trying to optimize what we have now. There isn't really a good way to truncate the source preview without making a breaking change to the user experience and if we're going to do that we might as well consider other options, like auto-selecting columns the way @lukasolson mentioned. So I'm going to close this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants