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

Split find_image_or_metadata API into two separate APIs #21289

Closed
jdm opened this issue Jul 30, 2018 · 32 comments
Closed

Split find_image_or_metadata API into two separate APIs #21289

jdm opened this issue Jul 30, 2018 · 32 comments

Comments

@jdm
Copy link
Member

@jdm jdm commented Jul 30, 2018

find_image_or_metadata serves two purposes today - learn about the state of the cache right now, and reserve a spot in the cache if there is not already an entry. This makes understanding how callers use it complicated, and it makes it easy to forget to add listeners for existing incomplete cache entries. We should redesign it:

  • get_image should return an Option<Image> which indicates that there is either a cached, fully loaded image, or not
  • track_image should accept a sender argument, which will be stored in the image cache just like the ImageCache::add_listener API. track_image will return a ImageCacheResult enum with the following states:
  • Available(ImageOrMetadataAvailable) (if only metadata is available)
  • LoadError
  • Pending
  • ReadyForRequest(PendingImageId)

The Available(ImageOrMetadataAvailable::Image) and LoadError states will result in the sender being dropped, since no more updates for that cache entry are expected. All other states will result in the sender being stored in the cache entry. This will make it impossible for a consumer to accidentally forget to add a cache listener for any state.

@jdm
Copy link
Member Author

@jdm jdm commented Jul 30, 2018

It's possible we could split this further into APIs that are allowed to load a placeholder and those that aren't, and reduce the set of possible responses that be received in the case where a placeholder image is not allowed.

@BK1603
Copy link

@BK1603 BK1603 commented Sep 10, 2018

I'd like to work on this!
Thanks a lot @jdm for helping me find this

@jdm jdm added the C-assigned label Sep 10, 2018
@BK1603
Copy link

@BK1603 BK1603 commented Sep 18, 2018

@jdm
Just to let you know:
I am still working on this, i've read a lot of the codebase in order to know about what i need to know, one of the functions is done, doing the second one and figuring out calls, will probably need help with that

And I apologoze for taking too long 😅

Thanks once again for all the help

@jdm
Copy link
Member Author

@jdm jdm commented Sep 18, 2018

No need to apologise! Thanks for letting us know.

@BK1603
Copy link

@BK1603 BK1603 commented Sep 23, 2018

@jdm,
I am not able to build servo on my machine. I have tried a lot of stuff but I still am stuck 😅
Here is the error code, can you help me please? 😅

error: linking with cc failed: exit code: 1

= note: collect2: fatal error: ld terminated with signal 6 [Aborted], core dumped
compilation terminated.
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc

@jdm
Copy link
Member Author

@jdm jdm commented Sep 23, 2018

That looks like you're running out of RAM while building.

@BK1603
Copy link

@BK1603 BK1603 commented Sep 23, 2018

@jdm,
Even at 6.5 gigs??
I have a minimal linux installation in an 8 gigs machine, it should get at least 6.5 in all cases, how much ram do i need?
Is this some bug?
What do i do now? 😅

@jdm
Copy link
Member Author

@jdm jdm commented Sep 23, 2018

We definitely exceed 6gb of used RAM at times during compilation. I don't know what to suggest :/

@BK1603
Copy link

@BK1603 BK1603 commented Sep 23, 2018

@jdm, oh okay
Got it
I will think of something then 😅
Like i will tell you soon if i am able to do sonething, else you can just unassign this issue again 😅

I'll try something and let you know

Thanks once again 😄

@BK1603
Copy link

@BK1603 BK1603 commented Sep 25, 2018

@jdm,
I tried doing a lot of stuff and ended up increasing the swap partition of my linux system, for which I had to format my laptop and reinstall everything, it does work but right now building on my laptop is like hours long, cause when the ram is completely filled up the system gets really slow, I don't think I will be able to build and debug as efficiently then 😅

It won't be a problem if you unassign the issue for now, I am trying out a few more things (one of them being convincing my parents for giving me the money for upgrading the RAM 😅 ), but I think they will take a lot of time, and I already have taken 15 days on this, it won't be a problem if someone else is able to fix this before me 😄

I hope I will be able to fix everything soon and make a PR, like I really want to do it 😅 but for now I guess I have to try and find a workaround, or get my RAM upgraded.

@jdm
Copy link
Member Author

@jdm jdm commented Sep 25, 2018

Ok! Sorry it's caused so much trouble for you!

@jdm jdm removed the C-assigned label Sep 25, 2018
@BK1603
Copy link

@BK1603 BK1603 commented Sep 25, 2018

@jdm,
It's absolutely fine, I don't think it's any of ours fault 😄

Also it was quite fun interacting there on irc and working on such a huge project, I'd say
Thanks a lot! 😄

@germangb
Copy link
Contributor

@germangb germangb commented Jan 18, 2019

Hi @BK1603 Are you still interested in working on this issue?

@iulianR
Copy link
Contributor

@iulianR iulianR commented Apr 11, 2019

Hi! Is it fine if I work on this issue? Thank you!

@jdm
Copy link
Member Author

@jdm jdm commented Apr 11, 2019

@iulianR Yes please!

@iulianR
Copy link
Contributor

@iulianR iulianR commented Apr 11, 2019

@highfive: assign me

@highfive highfive added the C-assigned label Apr 11, 2019
@highfive
Copy link

@highfive highfive commented Apr 11, 2019

Hey @iulianR! Thanks for your interest in working on this issue. It's now assigned to you!

@iulianR
Copy link
Contributor

@iulianR iulianR commented Apr 14, 2019

Started working on this and I have some questions related to the sender argument for track_image.

The way I see it, currently htmlimagelement.rs and htmlvideoelement.rs use add_cache_listener_for_element when find_image_or_metadata returns Pending, which creates an ImageResponder and calls add_listener with that image listener as sender.

Should I rename add_cache_listener_for_element and have it return the ImageResponder which I would then pass to track_image, which in turn calls add_listener? Also, should add_listener still be public?

@jdm
Copy link
Member Author

@jdm jdm commented Apr 16, 2019

@iulianR Yes, that sounds like a reasonable way to structure the code. There's one other use of add_listener in window.rs right now which it's not clear if we can replace with the new APIs, so I don't think we can make it private yet.

@jdm
Copy link
Member Author

@jdm jdm commented May 22, 2019

@iulianR Are you still working on this?

@iulianR
Copy link
Contributor

@iulianR iulianR commented May 22, 2019

I was unable to finish it in the free days I had then and unfortunately, I do not have the required time to finish it now. It can be assigned to someone else.

@jdm jdm removed the C-assigned label May 22, 2019
@rileylyman
Copy link

@rileylyman rileylyman commented Jun 10, 2019

Hi, I would like to take this issue. Let me know if that's okay!

@jdm
Copy link
Member Author

@jdm jdm commented Jun 10, 2019

Please do!

@julientregoat
Copy link
Contributor

@julientregoat julientregoat commented Jun 28, 2019

hey since it looks like you haven't started yet, mind if I do @rileylyman?

@highfive: assign me

EDIT: ps @jdm this may take me some time since I'm still really fresh to the codebase. if there's someone more appropriate to fill this issue, I'm happy to concede it!

@highfive highfive added the C-assigned label Jun 28, 2019
@highfive
Copy link

@highfive highfive commented Jun 28, 2019

Hey @julientregoat! Thanks for your interest in working on this issue. It's now assigned to you!

@jdm
Copy link
Member Author

@jdm jdm commented Jun 28, 2019

You are welcome to take your time with it :)

@julientregoat
Copy link
Contributor

@julientregoat julientregoat commented Jun 29, 2019

hey @jdm , wrote some code tonight, and I think I got it going. can you tell me if I'm heading in the right direction by checking my code? building correctly so that's good at least. I plan on updating to to the v2 you mentioned later on. anyway, thanks a ton, appreciate it! wanted to confirm before I go arounf fixing the others

link to code

@jdm
Copy link
Member Author

@jdm jdm commented Jun 29, 2019

Yes, that seems like the right idea!

@julientregoat
Copy link
Contributor

@julientregoat julientregoat commented Jun 30, 2019

@jdm Okay so I'm refactoring the functions that previously called find_image_or_meta atm. Currently, it looks like if any of them require access to the image, it's generally as Arc<Image>. It seems like it would be better to return an Option<Arc<Image>> from ImageCache::get_image, which unwraps it from an Arc anyway - does that work?

Also, a few of those same functions usually do something with the PendingImageId in the event that the image is still pending. Would it be ok to have the enum as ImageCacheResult::Pending(PendingImageId)?

@jdm
Copy link
Member Author

@jdm jdm commented Jun 30, 2019

@julientregoat If the consumers want an Arc, then that seems like a reasonable change. As for the question about the Pending variant, do the functions do anything besides call add_listener? I would expect that functionality to become part of track_image automatically.

@julientregoat
Copy link
Contributor

@julientregoat julientregoat commented Jun 30, 2019

@jdm

  • In LayoutContext::get_or_request_image_or_meta, it uses the id to construct a PendingImage and add it to its internal pending_images vector.
  • In HTMLImageElement::react_to_environment_changes_sync_steps, on Pending it does call add_cache_listener_for_element, which I recognize also calls ImageCache::add_listener inside like ImageCache::track_image, however I wasn't sure if that served a different purpose because of the extra logic within the function - seemed like custom ipc messaging & routing logic
  • Same as above for HTMLVideoElement::fetch_poster_frame
@jdm
Copy link
Member Author

@jdm jdm commented Jun 30, 2019

Good point! Seems reasonable to include it for the time being, in that case.

@jdm jdm added the C-has open PR label Jul 23, 2019
bors-servo added a commit that referenced this issue Nov 17, 2019
Refactor ImageCache::find_image_or_metadata -> ImageCache::{get_image, track_image}

<!-- Please describe your changes on the following line: -->
Updated the `ImageCache` trait to replace `find_image_or_metadata` with two new functions `track_image` and `get_image`, as well as a new enum (`ImageCacheResult`).

As a result, I was able to refactor the functions that previously called `find_image_or_metadata` pretty cleanly. For a list of these functions, please see the commit information.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21289  (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because tests already exist for these components. I ran `cargo test` in `net`, `net_traits`, `layout`, and `script` successfully.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23661)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Nov 19, 2019
Refactor ImageCache::find_image_or_metadata -> ImageCache::{get_image, track_image}

<!-- Please describe your changes on the following line: -->
Updated the `ImageCache` trait to replace `find_image_or_metadata` with two new functions `track_image` and `get_image`, as well as a new enum (`ImageCacheResult`).

As a result, I was able to refactor the functions that previously called `find_image_or_metadata` pretty cleanly. For a list of these functions, please see the commit information.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21289  (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because tests already exist for these components. I ran `cargo test` in `net`, `net_traits`, `layout`, and `script` successfully.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23661)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Jan 20, 2020
Refactor ImageCache::find_image_or_metadata -> ImageCache::{get_image, track_image}

<!-- Please describe your changes on the following line: -->
Updated the `ImageCache` trait to replace `find_image_or_metadata` with two new functions `track_image` and `get_image`, as well as a new enum (`ImageCacheResult`).

As a result, I was able to refactor the functions that previously called `find_image_or_metadata` pretty cleanly. For a list of these functions, please see the commit information.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21289  (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because tests already exist for these components. I ran `cargo test` in `net`, `net_traits`, `layout`, and `script` successfully.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23661)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Jan 22, 2020
Refactor ImageCache::find_image_or_metadata -> ImageCache::{get_image, track_image}

<!-- Please describe your changes on the following line: -->
Updated the `ImageCache` trait to replace `find_image_or_metadata` with two new functions `track_image` and `get_image`, as well as a new enum (`ImageCacheResult`).

As a result, I was able to refactor the functions that previously called `find_image_or_metadata` pretty cleanly. For a list of these functions, please see the commit information.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21289  (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because tests already exist for these components. I ran `cargo test` in `net`, `net_traits`, `layout`, and `script` successfully.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23661)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Feb 21, 2020
Refactor ImageCache::find_image_or_metadata -> ImageCache::{get_image, track_image}

<!-- Please describe your changes on the following line: -->
Updated the `ImageCache` trait to replace `find_image_or_metadata` with two new functions `track_image` and `get_image`, as well as a new enum (`ImageCacheResult`).

As a result, I was able to refactor the functions that previously called `find_image_or_metadata` pretty cleanly. For a list of these functions, please see the commit information.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21289  (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because tests already exist for these components. I ran `cargo test` in `net`, `net_traits`, `layout`, and `script` successfully.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23661)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Feb 21, 2020
Refactor ImageCache::find_image_or_metadata -> ImageCache::{get_image, track_image}

<!-- Please describe your changes on the following line: -->
Updated the `ImageCache` trait to replace `find_image_or_metadata` with two new functions `track_image` and `get_image`, as well as a new enum (`ImageCacheResult`).

As a result, I was able to refactor the functions that previously called `find_image_or_metadata` pretty cleanly. For a list of these functions, please see the commit information.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21289  (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because tests already exist for these components. I ran `cargo test` in `net`, `net_traits`, `layout`, and `script` successfully.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23661)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Feb 27, 2020
Refactor ImageCache::find_image_or_metadata -> ImageCache::{get_image, track_image}

<!-- Please describe your changes on the following line: -->
Updated the `ImageCache` trait to replace `find_image_or_metadata` with two new functions `track_image` and `get_image`, as well as a new enum (`ImageCacheResult`).

As a result, I was able to refactor the functions that previously called `find_image_or_metadata` pretty cleanly. For a list of these functions, please see the commit information.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21289  (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because tests already exist for these components. I ran `cargo test` in `net`, `net_traits`, `layout`, and `script` successfully.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23661)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Feb 27, 2020
Refactor ImageCache::find_image_or_metadata -> ImageCache::{get_image, track_image}

<!-- Please describe your changes on the following line: -->
Updated the `ImageCache` trait to replace `find_image_or_metadata` with two new functions `track_image` and `get_image`, as well as a new enum (`ImageCacheResult`).

As a result, I was able to refactor the functions that previously called `find_image_or_metadata` pretty cleanly. For a list of these functions, please see the commit information.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21289  (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because tests already exist for these components. I ran `cargo test` in `net`, `net_traits`, `layout`, and `script` successfully.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23661)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Apr 17, 2020
Refactor ImageCache::find_image_or_metadata -> ImageCache::{get_image, track_image}

<!-- Please describe your changes on the following line: -->
Updated the `ImageCache` trait to replace `find_image_or_metadata` with two new functions `track_image` and `get_image`, as well as a new enum (`ImageCacheResult`).

As a result, I was able to refactor the functions that previously called `find_image_or_metadata` pretty cleanly. For a list of these functions, please see the commit information.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21289  (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because tests already exist for these components. I ran `cargo test` in `net`, `net_traits`, `layout`, and `script` successfully.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23661)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this issue Apr 17, 2020
Refactor ImageCache::find_image_or_metadata -> ImageCache::{get_image, track_image}

<!-- Please describe your changes on the following line: -->
Updated the `ImageCache` trait to replace `find_image_or_metadata` with two new functions `track_image` and `get_image`, as well as a new enum (`ImageCacheResult`).

As a result, I was able to refactor the functions that previously called `find_image_or_metadata` pretty cleanly. For a list of these functions, please see the commit information.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #21289  (GitHub issue number if applicable)

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because tests already exist for these components. I ran `cargo test` in `net`, `net_traits`, `layout`, and `script` successfully.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23661)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

7 participants
You can’t perform that action at this time.