Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
block.module
Priority:
Major
Category:
Task
Assigned:
Issue tags:
Reporter:
Created:
15 Nov 2014 at 01:08 UTC
Updated:
4 May 2015 at 09:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
tim.plunkettComment #2
alexpottTagging
Comment #3
tstoecklerSeems like this is no longer postponed?
Just found this from the code comment in BlockBase::access()
Comment #4
Anonymous (not verified) commentedIs this issue allowed during the beta phase? Will it be a performance gain, thus prioritising the issue? Wouldn't it be disruptive since it's a widespread task?
Comment #5
wim leersTentatively marking major, because IIRC the flamecharts showed a significant portion of time was spent in checking block access.
Comment #6
dawehnerDecided to go with keeping
blockAccess(). This makes it a) a bit easier to write the method in the first place and b) makes it easier to adapt existing code.... In general I think we should reavulate to #5 because I can't really believe that access itself is slow ... it always used to be, if I remember correctly, the fact, that access
used to be visibility rules as well, which had a broken context injection.
Comment #8
eclipsegc commented@wim, those flame charts were because context was gathered for each block individually, that is no longer true. Unless someone has reworked the flame charts to prove this, I'm not sure this is major.
That being said, the logical split between these two functions exists for the sake of making it less likely that a module implementing block plugins would accidentally side-step the entire block access process by making a single function that represents the block's specific access logic. That split still seems relevant to me unless someone has a really good argument to the contrary.
On the one hand I want to agree, on the other hand, we just increased the amount of code every block implementer must write.
Case in point, the rest of this patch... does this really benefit us from a caching perspective?
Eclipse
Comment #9
tim.plunkettI need to look at the patch more to have a stronger opinion on making that abstract or not, but I agree that we should not remove the split.
Comment #10
berdirAccess *can* be slow.
Especially at the moment, where access is the only way to prevent a block from being shown (there's an issue for it, in 7.x you could simply return nothing and the block wasn't shown, now you need to implement access for that.. e.g. an empty view).
I'm not entirely sure how access caching would work, but if it would, then we could possibly cache entire page_manager pages without having to load the blocks, their contexts and asking them about access, that would be very interesting.
But yes, we will have to argue why this issue needs to be major to make it in, a normal issue with a change like that is probably not going to work.
Comment #11
dawehnerWell, the problem is that with late rendering, we don't know in beforehand, whether a block is empty or not.
Comment #12
wim leersI think that by that you mean the whole
$return_as_objectthing, right?Comment #13
wim leersReroll to fix a bunch of nitpicks and a todo.
EDIT: I created an interdiff, but forgot to upload it, and now it's gone. Sorry.
Comment #15
wim leersAt least major, because this blocks #2429617: Make D8 2x as fast: Dynamic Page Cache: context-dependent page caching (for *all* users!).
Comment #16
wim leersComment #17
fabianx commentedThis is a blocker indeed ...
Comment #18
berdirThis means that we need to execute the entity query to get the block id from the uuid to load it twice, there is currently no caching for that, static or otherwise.
Not sure how good that pattern is, but maybe the block content block should do the same and store the loaded entity?
We could a the list tag for configurable languages, not sure if that's worth it?
Nice trick to get the relevant cache tags, but not exactly obvious that you have to do something like this. Implementing access correctly is quite challenging.
Do we really want to change the default? A lot of blocks have the default implementation copy & pasted.
Comment #19
arla commentedComment #20
arla commentedRerolled and re-added BlockBase::blockAccess(). Added getEntity() to BlockContentBlock, so the entity is loaded once only. Added the list cache tag to the LanguageBlock access result.
Comment #22
wim leersLooking great! This is pretty close :)
Let's add a comment here to document why
BlockBasehas this method. Something like:We should remove this line now.
I think the
$uuid = …line there is now no longer necessary? :)Nit: We put a newline between the closing brace of the last method and the closing brace of the class.
Comment #23
arla commented1. Yes. Added, with a slightly different wording.
2. Oh.. setCacheMaxAge(0) basically says "not cacheable", right? Fixed.
3. Right, fixed.
4. Fixed.
@Berdir also pointed out a few things that should reduce the test fail count, in BlockContentBlock and UserLoginBlock.
Comment #25
arla commentedOh, access() returns bool by default. Fixed.
Comment #26
wim leers2. Yep :)
One small thing left :) Almost done!
'user.permissions' is not correct. This does not check the permissions, it checks whether the current user has the 'anonymous role. So the right cache context here is actually 'user.roles:anonymous'.
Comment #27
wim leersComment #30
arla commentedCorrected the cache context.
Comment #31
wim leersExcellent!
Comment #32
wim leersComment #33
arla commentedAdded beta evaluation. Hope I got it right.
Comment #34
wim leersComment #35
alexpottShouldn't this be in the documentation on the interface?
Unrelated change
Comment #36
arla commentedMoved/rephrased the comment and undid unrelated changes.
Comment #37
wim leersComment #38
webchickLooks straight-forward to me, although it's weird that blocks have this blockAccess() method and other entities do not. However, that's a pre-existing condition, and at least there are docs about it now.
Committed and pushed to 8.0.x. Thanks!
Comment #40
wim leersCR added: https://www.drupal.org/node/2472583
Comment #41
wim leersThis made the frontpage a millisecond slower, but we needed it for correctness.
Comment #42
berdirA millisecond? I'm not sure I see why, we're basically doing the same thing as before? That would mean that merging access results with metadata is so expensive?
Comment #43
wim leersWell, I don't know 100% certain this caused it. But I'm seeing way more time being spent in
BlockAccessControlHandler, which is initializing a bunch of things it didn't before.I assumed it was this patch, I didn't do the necessary digging to be 100% certain.
Comment #44
fabianx commentedbelated: RTBC + 1
If this makes core a little slower that is fine and probably indeed the inheritCacheability calls, but we can still optimize those ...