Topic: viewtopic.php - Cache avatar?

In viewtopic, would it be worth it to cache the avatar information after the initial avatar checking similar to $signature_cache. In a thread, a user may appear more than once, then the avatar checking is done each time for the same information.

Re: viewtopic.php - Cache avatar?

Probably: reducing unnecessary I/O is always a good thing.

3

Re: viewtopic.php - Cache avatar?

Just out of curiosity, with regards to this in 1.2*, where is the sig caching done? Just grepped for it, and all I found were these three lines:

viewtopic.php:303:              if (isset($signature_cache[$cur_post['poster_id']]))
viewtopic.php:304:                      $signature = $signature_cache[$cur_post['poster_id']];
viewtopic.php:308:                      $signature_cache[$cur_post['poster_id']] = $signature;

Re: viewtopic.php - Cache avatar?

And those are the three lines wink
It's not a cache in the same sense as the cache PHP files, it just saves the already parsed signature for use later, so we don't have the overhead of parsing the same signature more than once.
In the same way, an avatar cache would save the already found correct img tag so that we don't have to check for file size, etc more than once.

5

Re: viewtopic.php - Cache avatar?

Another of my muppet moments. big_smile The penny never dropped when looking at the code.

Re: viewtopic.php - Cache avatar?

Is there a reason why this information isn't cached in the db?

Re: viewtopic.php - Cache avatar?

Currently, uploading an avatar in 1.3 just involves moving files around. We removed use_avatar from the schema, since it really served no purpose. Storing avatar information (be it the entire img tag, just the filename, etc) doesn't help much, since we're just duplicating information that already exists (and our information may be out of date, since an administrator could delete an avatar manually via shell or FTP).

Re: viewtopic.php - Cache avatar?

Well i was thinking if you assume the admin doesn't touch the avatar files it would get rid of a lot of file operations if you cached the info you get from them

Re: viewtopic.php - Cache avatar?

If it turns out that the file operations are actually significantly slowing down viewtopic.php, then it might be worth looking at. However, I have a feeling that they're not. Thus, reducing unnecessary repetition of them has all the upsides of actually caching the HTML in the users table without any of the downsides. smile

Re: viewtopic.php - Cache avatar?

Sounds good tongue

Re: viewtopic.php - Cache avatar?

Smartys wrote:

If it turns out that the file operations are actually significantly slowing down viewtopic.php, then it might be worth looking at. However, I have a feeling that they're not. Thus, reducing unnecessary repetition of them has all the upsides of actually caching the HTML in the users table without any of the downsides. smile

Sorry to be dense. smile Is the final decision to keep it as it? Thanks.

Re: viewtopic.php - Cache avatar?

No, the "final decision" (I put it in quotes because it's not the final decision, it's my opinion) is that an avatar cache like the signature cache is a good idea to cut down on unnecessary I/O, while caching the HTML in the users table is something we should do only if the reduced number of calls still slows down viewtopic.php a great deal.

Re: viewtopic.php - Cache avatar?

Caching the html in the database wouldn't do much of a difference, or am I missing something?

echo $cur_topic['avatar'];

if( $cur_topic['avatar'] != '' )
    echo '<img src="'.$cur_topic['avatar'].'"/>';

As I see it, caching the html would require two fields, the html and the path to the avatar, while caching the url/path instead requires just one, and gives the same performance.

Hmm, someone might already have said this.

As for file_exists vs db fields go, there is some upsides to db fields. One is external avatars, and avatars from different systems. File_exists requires workarounds or editing the code, while a db field can be changed by an extensions quite easily.

Re: viewtopic.php - Cache avatar?

intedinmamma: The idea is to completely avoid file I/O. So you can't just store the path, since we also check the image to get the proper width/height. wink

As for file_exists vs db fields go, there is some upsides to db fields. One is external avatars, and avatars from different systems. File_exists requires workarounds or editing the code, while a db field can be changed by an extensions quite easily.

Except that an external avatar system, if properly implemented, is always going to suffer from performance issues. That's because avatars need to be validated for width/height/size restrictions on every pageview, which is much worse when the images aren't actually on the server.
And the hook system should really make developing such an extension easier anyway (although you would need an extra database column).

Re: viewtopic.php - Cache avatar?

Smartys: So cache the width/height then? You'll just have to recache it when you upload a new avatar, and that's it. External avatars is, well, a bad example. roll

Btw, viewtopic needs keys on $pun_page['user_ident'] and $pun_page['user_info'], or you'll just have to assume the key for the avatar, and all the other info. Especially if you're using some other extension which adds links/info/whatever.

Re: viewtopic.php - Cache avatar?

So cache the width/height then? You'll just have to recache it when you upload a new avatar, and that's it.

Yes. That's caching the entire HTML tag. And as I said, that comes with some downsides (increases complexity of the uploading process, leads to duplication of data, leads to PunBB using possibly incorrect data). The only real impetus to use that method would be if the benefits in terms of reduced I/O really speed up pageviews, which I don't think it will. smile

Btw, viewtopic needs keys on $pun_page['user_ident'] and $pun_page['user_info'], or you'll just have to assume the key for the avatar, and all the other info. Especially if you're using some other extension which adds links/info/whatever.

It's something we need to investigate to see if we can improve on. Obviously non-numeric keys would make finding elements of the array simpler (instead of needing to traverse the array). On the other hand, we need to see how easy it would then be to insert elements in the middle. Thanks for pointing it out though, I'll look into it now.

17

Re: viewtopic.php - Cache avatar?

I've been thinking about array keys as well. There have been a few instances where it would have been useful to use one or more elements from an array basically as if they were individual variables.

Re: viewtopic.php - Cache avatar?

Well, my testing has discovered a method by which it might be possible to use associative keys. Sweet! big_smile