php forum
php mysql forum
php mysql smarty
 
Topic Options
#130903 - 02/12/01 01:56 AM [6.0x] Faster Profile Retrieval
Leshrac Offline
Member

Registered: 01/03/00
Posts: 213
Loc: Berkeley, CA

   [6.0x] Faster Profile Retrieval to Del.icio.us Add to del.icio.us
  Digg [6.0x] Faster Profile Retrieval Digg it
Also posted at the UBB support forums, here .

"Until you start thinking in terms of hashes, your aren't really thinking in Perl." - Programming Perl, 2nd Ed., O'Reilly Books

Here's another speedup I stumbled upon, and much like the GetUserNumber speedup, I can't believe I didn't realize it earlier. This one is for the OpenProfile subroutine of ubb_lib.cgi, and operates on much the same concept of the GetUserNumber speedup, the difference being that is stores a hash of profile arrays instead of a hash of user numbers. The modification is deceptively simple for the speed increase it can give.

First off, you'll need to open up cp.cgi and ultimatebb.cgi and add %UserProfile to the list of variables in the use vars qw(...); string near the top of each file. Then, open up ubb_lib.cgi and find the following:
Code:
[/code]Right under that add:[code]
Then, at the end of that subroutine find:
Code:
[/code]Replace that with:[code]
So, what does this do? Well, it creates a global hash table of references to anonymous arrays. Each of these anonymous arrays contains the profile of some user, and the references to them are indexed by that user's member number. Whenever OpenProfile is called, it first checks to see if it has already read that profile from the file before, and if so, it grabs the reference to the anonymous array holding that profile, dereferences it, and passes it back to the calling function. If the profile hasn't already been read, it reads the profile array from the member's file as normal, and then stores a reference to an anonymous copy of that array in the hash table before returning it.

OK, now that we've got that settled, why is it any faster? Well, as you may or may not know, disk access is a relatively slow process compared to memory access. Any time you can access something out of memory as opposed to off of a disk, you should. This speedup stores profiles in memory after they've been read from the disk, and reads them back from the memory if they're already there. Say, for example, you have a thread where three people are participating in a conversation. One person has three posts on the thread, another two, and the last only one. Generating this thread would normally require six file accesses, whereas with this speedup it only requires three. This is just a simple example, as the OpenProfile subroutine is used all over the place in the code (50+ occurrences in Beta 7.7), and the savings can be much more significant, depending on the circumstances.

Here's hoping this makes it into the final release. cool
_________________________
Leshrac
leshrac@magictraders.com
http://www.MagicTraders.com

Top
#130904 - 02/12/01 07:05 AM Re: [6.0x] Faster Profile Retrieval
Jigga-Master Offline
Member

Registered: 10/08/00
Posts: 985
Loc: Toronto
kool nice work!
anyone have a nenchmark?
_________________________

Top
#130905 - 02/12/01 07:22 PM Re: [6.0x] Faster Profile Retrieval
Greg Hard Offline
Member

Registered: 02/21/00
Posts: 5533
Loc: My Room
Old - 0.24
New - 0.12

WONDERFUL job Leshrac..

Top
#130906 - 02/13/01 02:18 AM Re: [6.0x] Faster Profile Retrieval
AllenAyres Administrator Offline
I type Like navaho

Registered: 03/10/00
Posts: 25408
Loc: Texas
Congrats on getting your code into the official version... laugh
_________________________
- Allen wavey
- What Drives You?

Top


Top Posters Last 30 Days
AllenAyres 18
Gizmo 12
sirdude 6
GEN 3
tackaberry 2
Philipp 2
willing 2
Who's Online
0 Registered (), 36 Guests and 9 Spiders online.
Key: Admin, Global Mod, Mod
Shout Box

Latest Posts
Team UBBDev Rides Again!
by Gizmo
08/28/08 11:45 PM
Multiple Identity Detector
by MattUK
08/28/08 04:10 PM
[7.3.x] ubb.links
by AllenAyres
08/26/08 09:57 AM
Installing FlashChat with 7.3
by Gizmo
08/23/08 05:36 AM
[7.2.1] - Naked shoutbox
by Iann128
08/22/08 07:27 PM
Nice Ajax Chat
by M4D
08/21/08 10:02 PM
51-card NVIDIA folding rig cranks out 265,200 ppd
by AllenAyres
08/13/08 10:10 PM
New Mods
Installing FlashChat with 7.3
by Paug
08/23/08 12:14 AM
[7.x] AddThis - Social Networking
by Gizmo
08/01/08 01:30 AM
[7.3.x] ubb.links
by AllenAyres
06/20/08 11:50 PM
[7.3] Dissallow quotes more then 3 levels deep
by blaaskaak
06/09/08 09:01 AM
[7.2.1] - Naked shoutbox
by sirdude
08/17/07 10:36 PM
Newest Members
welcomeback1, Paug, Tim Keating, anscers, Murphdog
13324 Registered Users

 

 

 
fusionbb message board php hacks