Allow caching various objects (take 2) by Manishearth · Pull Request #1088 · immersive-web/webxr · GitHub
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

Allow caching various objects (take 2) #1088

Merged
merged 2 commits into from
Jun 26, 2020

Conversation

Manishearth
Copy link
Contributor

@Manishearth Manishearth commented Jun 19, 2020

Fixes #1010

Second attempt at #1086

This PR only caches:

  • XRViewport obejcts when the viewport has not changed
  • XRFrame objects for animation frames

We determined that caching poses is probably too dangerous since they're "plain old data" types that folks may choose to hold on to. Leaving #1086 as a separate PR if people are interested in seeing how that would work.

cc @asajeffrey @MortimerGoro @cabanier


Preview | Diff

index.bs Outdated
1. Let |viewport| be a [=new=] {{XRViewport}} in the [=relevant realm=] of |layer|'s [=XRWebGLLayer/session=].
1. Initialize |viewport| as follows:
<dl class="switch">
<dt>If a |view| with the same underlying [=view=] has been passed to a getViewport() call previously, and |glViewport| has not changed since then, the user agent MAY:</dt>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This MAY can probably safely be a MUST

index.bs Outdated
1. Let |viewport| be a [=new=] {{XRViewport}} in the [=relevant realm=] of |layer|'s [=XRWebGLLayer/session=].
1. Initialize |viewport| as follows:
<dl class="switch">
<dt>If a |view| with the same underlying [=view=] has been passed to a getViewport() call previously, and |glViewport| has not changed since then, the user agent MAY:</dt>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<dt>If a |view| with the same underlying [=view=] has been passed to a getViewport() call previously, and |glViewport| has not changed since then, the user agent MAY:</dt>
<dt>If a |view| with the same underlying [=view=] has been passed to this |layer|'s getViewport() call previously, the user agent MAY:</dt>

Is "with the same underlying [=view=]" needed?

Copy link
Member

Choose a reason for hiding this comment

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

Probably, since XRViews aren't a good candidate for caching. (The transform and projectionMatrix make them closer to a POD structure like XRPose than an opaque key, though I made that same mistake in the previous PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cabanier yes, you have a different XRView object each frame

index.bs Outdated
1. Let |frame| be a [=new=] {{XRFrame}} with [=XRFrame/time=] |frameTime| and {{XRFrame/session}} |session| in the [=relevant realm=] of |session|.
1. Initialize |frame| as follows:
<dl class="switch">
<dt>If |session| has previously run an [=XR animation frame=], the user agent MAY:</dt>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This MAY could be a MUST, which would prevent content that stashes stuff on frames from behaving differently on different browsers (though content shouldn't really be relying on that anyway).

But we should definitely check with UAs before doing this

@Manishearth
Copy link
Contributor Author

/agenda To discuss how people feel about unconditionally caching, and whether there's anything that can be done about poses

@probot-label probot-label bot added the agenda Request discussion in the next telecon/FTF label Jun 19, 2020
@Manishearth
Copy link
Contributor Author

In the call Rik pointed out that DOM uses a "may" for this in getElementsByTagName(), however that's probably because those APIs have a large set of potential return values and caching them all would be hard. Over here we're caching a single XRFrame and 1-2 XRViewport values.

@cabanier
Copy link
Member

Maybe we need to get input from the TAG on this, especially if we're the first spec to mandate the return of the same object.

@Manishearth
Copy link
Contributor Author

@cabanier I don't think that's anything special, e.g. both things can be better specified by caching the frame and viewports on the session.

But I'm open to using a MAY here either way.

@cabanier
Copy link
Member

I prefer a MAY.
For WebXR layers, we store weak pointers to temporary objects so it is possible that the object was GC'ed between frames.

@Yonet Yonet removed the agenda Request discussion in the next telecon/FTF label Jun 25, 2020
@Manishearth
Copy link
Contributor Author

Manishearth commented Jun 26, 2020

I've updated the text to use MUST after discussing with Brandon. There's a nicer way to spec this so that we're not really mandating "the same object", but that's a purely editorial thing that I'm going to file a followup about.

@Manishearth Manishearth merged commit e07923f into immersive-web:master Jun 26, 2020
@Manishearth Manishearth deleted the caching2 branch June 26, 2020 17:07
@Manishearth
Copy link
Contributor Author

Opened #1090 to improve the text and make the caching more explicit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Garbage collecting objects that are generated every frame
4 participants