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

Screenshot: stop repeating the same screenshot over and over when it doesn't change #2949

Open
julienw opened this issue Oct 14, 2020 · 15 comments
Labels
help wanted Things ready to be worked on by anyone. Issues must include instructions on how to complete the task markers Anything to do with marker data structures, marker chart, or the marker table timeline Issues related to the header timeline view

Comments

@julienw
Copy link
Contributor

julienw commented Oct 14, 2020

In this patch we want to do an experiment, it's not sure we'll land this in the end.
This experiment is that we don't want that we repeat the screenshot in the screenshot track, if it doesn't change.

The current logic is at

render() {
const {
thread,
width: outerContainerWidth,
rangeStart,
rangeEnd,
screenshots,
trackHeight,
} = this.props;
if (screenshots.length === 0) {
return null;
}
const images = [];
const rangeLength = rangeEnd - rangeStart;
const imageContainerWidth = trackHeight * 0.75;
const timeToPixel = time =>
(outerContainerWidth * (time - rangeStart)) / rangeLength;
const leftmostPixel = Math.max(timeToPixel(screenshots[0].start), 0);
let screenshotIndex = 0;
for (
let left = leftmostPixel;
left < outerContainerWidth;
left += imageContainerWidth
) {
// Try to find the next screenshot to fit in, or re-use the existing one.
for (let i = screenshotIndex; i < screenshots.length; i++) {
if (timeToPixel(screenshots[i].start) <= left) {
screenshotIndex = i;
} else {
break;
}
}
// Coerce the payload into a screenshot one.
const payload: ScreenshotPayload = (screenshots[screenshotIndex]
.data: any);
const { url: urlStringIndex, windowWidth, windowHeight } = payload;
const scaledImageWidth = (trackHeight * windowWidth) / windowHeight;
images.push(
<div
className="timelineTrackScreenshotImgContainer"
style={{ left, width: imageContainerWidth }}
key={left}
>
{/* The following image is centered and cropped by the outer container. */}
<img
className="timelineTrackScreenshotImg"
src={thread.stringTable.getString(urlStringIndex)}
style={{
width: scaledImageWidth,
height: trackHeight,
}}
/>
</div>
);
}
return images;
}
}

What it does is that for each pixel we try to find the right screenshot. Especially here:

for (let i = screenshotIndex; i < screenshots.length; i++) {
if (timeToPixel(screenshots[i].start) <= left) {
screenshotIndex = i;
} else {
break;
}
}

We see that if don't find a screenshot, by breaking we reuse the previous data.

We also see that there are 2 nested loops: the outer loop loops over the pixel "left" information, and the inner loops over the screenshots.

Instead I think we'll want to invert the logic: the outer loop looping over the screenshots, and some logic inside to compute the "left" information. Especially take care that we don't overlap images, so when looping over the screenshots you'll need to skip them until we have some space. When finally we have some space we'll need to display the last screenshot.

Maybe that's not the easiest solution, and instead we should just change something at the break in the existing code. So this will need some research.

Here are some profile links containing screenshots:

┆Issue is synchronized with this Jira Task

@julienw julienw added help wanted Things ready to be worked on by anyone. Issues must include instructions on how to complete the task timeline Issues related to the header timeline view labels Oct 14, 2020
@raymond-sikpojie
Copy link
Contributor

Can I give this a try? @julienw

@lorelajano
Copy link
Contributor

Can I work on this?

@julienw
Copy link
Contributor Author

julienw commented Oct 14, 2020

Hey @raymond-sikpojie, yes sure!
@lorelajano as you see, this issue is taken already, thanks for your understanding.

@julienw julienw added the assigned A developer has requested to work on this issue. label Oct 14, 2020
@julienw julienw added the markers Anything to do with marker data structures, marker chart, or the marker table label Oct 14, 2020
@raymond-sikpojie
Copy link
Contributor

Hey @julienw. I tried but I really don't know how to go about this one. Can I be unassigned from this issue? Thanks

@raymond-sikpojie raymond-sikpojie removed their assignment Oct 19, 2020
@ghost
Copy link

ghost commented Oct 19, 2020

@julienw can i give this a go?

@canova canova assigned ghost Oct 19, 2020
@canova
Copy link
Member

canova commented Oct 19, 2020

Sure @karenefereyan, let us know if you need anything!

@julienw
Copy link
Contributor Author

julienw commented Dec 3, 2020

hey @karenefereyan, is that still something you'd like to work on? It's totally OK if you don't, but please tell us so that we can reset the status of this issue. Thanks!

@ghost
Copy link

ghost commented Dec 3, 2020

hey @karenefereyan, is that still something you'd like to work on? It's totally OK if you don't, but please tell us so that we can reset the status of this issue. Thanks!

@julienw please reassign it to someone else as I'm having some technical challenges currently

@julienw
Copy link
Contributor Author

julienw commented Dec 4, 2020

No worries, thanks for telling us :-)

@julienw julienw unassigned ghost Dec 4, 2020
@julienw julienw removed the assigned A developer has requested to work on this issue. label Dec 4, 2020
@Bucky25
Copy link
Contributor

Bucky25 commented Dec 17, 2020

@julienw i would like to work on it.

@Bucky25
Copy link
Contributor

Bucky25 commented Dec 17, 2020

what exactly is the task is it to only show the screen shot and if it is not changing then we do not show it until the new screenshot has a change relative to previous one . do i got it wright or correct me if i am wrong . and what to show if the screenshot does not changes .

@julienw
Copy link
Contributor Author

julienw commented Dec 18, 2020

what exactly is the task is it to only show the screen shot and if it is not changing then we do not show it until the new screenshot has a change relative to previous one . do i got it wright or correct me if i am wrong . and what to show if the screenshot does not changes .

Yes, this is exactly this!

If the screenshot does not change, I believe this could just be "blank", nothing drawn. We can decide later if we want to change the background to something grey instead of white, but that's easy to do later.

@julienw julienw added the assigned A developer has requested to work on this issue. label Dec 18, 2020
@Bucky25
Copy link
Contributor

Bucky25 commented Dec 19, 2020

@julienw how are we going to compare screenshots .

@Bucky25
Copy link
Contributor

Bucky25 commented Feb 6, 2021

@julienw hey can you help me with comparing screenshots

@julienw
Copy link
Contributor Author

julienw commented Mar 10, 2021

Hey @Bucky25, in this issue we don't want to compare? So I don't understand your question... Can you please explain this more?

@julienw julienw removed the assigned A developer has requested to work on this issue. label Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Things ready to be worked on by anyone. Issues must include instructions on how to complete the task markers Anything to do with marker data structures, marker chart, or the marker table timeline Issues related to the header timeline view
Projects
None yet
Development

No branches or pull requests

5 participants