|
Post by disabled on Jun 17, 2010 22:24:31 GMT
Once again, my vendetta against bad JS code. Take this:
var a = document.getElementsByTagName('a'); function changeName(username, displayname) { for(i=0; i<a.length; i++) { if(a.item(i).href.match(new RegExp('action=viewprofile&user='+username+'$', 'i'))) { a.item(i).innerHTML = displayname; } } } Five time execution with all the 37 names on the about board profiles to 1075.254ms, so ~200ms on average. Using this code:
var a = document.getElementsByTagName('a'); function changeName(username, displayname) { m = new RegExp('action=viewprofile&user='+username+'$', 'i'); for(i=0; i<a.length; i++) { if(a.item(i).href.match(m)) { a.item(i).innerHTML = displayname; } } } Again called five times 37 times, in only needs 6.488ms for all five runs. So its 166 times faster! So we conclude: building regexpes is Slow as hell.
To be continued (perhaps).
*edit* It would be nice, if I could have a copy the raw header and footer. Exactly knowing what I can modify and what not makes it so much easier...
|
|
|
Post by Qwerty on Jun 18, 2010 0:08:09 GMT
Okay, if you want to help us optimize the code feel free to help out. We got most of them from Proboards Support. Here's a copy: pastebin.com/nDictRJ6EDIT: That new code sorta broke the code for some reason. Changed back, any way to fix it?
|
|
|
Post by disabled on Jun 18, 2010 1:16:21 GMT
Ok, that was a little embarrassing. I wonder how I was able to test the code... But it did work and works now and its still faster. And thanks for the header/footer dump, might help a lot.
|
|
|
Post by Qwerty on Jun 18, 2010 4:59:42 GMT
It didn't work before, but it might now if you fixed it. You can test it by making another proboards and pasting in the H/F codes.
|
|
|
Post by disabled on Jun 18, 2010 6:34:19 GMT
|
|
|
Post by ~Memzak~ on Jun 18, 2010 7:30:52 GMT
Wow, go disabled!
You really, really know your stuff. *I even noticed a slight loading time difference*
|
|
|
Post by disabled on Jun 18, 2010 8:34:14 GMT
Must be a placebo effect, because the new code is not active yet
|
|
|
Post by ~Memzak~ on Jun 18, 2010 11:51:11 GMT
not on this forums on the other one.
|
|
|
Post by disabled on Jun 18, 2010 13:18:25 GMT
You can't really compare those loading times between the two. That regexp is originally generated for every link on the forum. My forum has much fewer threads and forums and thus much fewer links. But 200ms are quite noticable, only that each time you load the forum, different ads are loaded thus the loading time differs quite a lot anyways. Another note: I got that timing using a javascript profiler. They tend to skew the absolute results, but the tendency should be right.
|
|
|
Post by disabled on Jul 5, 2010 11:06:43 GMT
While I'm still waiting for this improvement to be implemented, I found the problem with the Polls. Of course the problem is not with Proboards, but the custom JS you included. Its in the Custom Star thingie. Here is a fixed code:
<script type="text/javascript">
// Custom stars go here. // var CStarNames = ["Black","Circle","Spinning","Sand","Heart","Chain","Toast","Rave", "Ereshkigal","Special","Spinning Red", "Flashing","MemzakStar","Blue Square","Fire","M4's 1","Phoenix","M4's 2","Bloody One","Rebel Insignia","Rainbow","Grey Pool","DM #4","QwertyStar","WN's","LOCKED!","Ganon's...","Qwerty's","Fire","Black Spinner","Rainbow Square","Pink Circle","Pickle","Spiral","TBP","TDM's","Shadow Lord's","MemzakStar2","KuraiOorora's","Artik's","Radioactive", "Ggoodie","EggStarMemzak", "Izacque Rolling Star","Val","M4's 3","Glove","Nmagain","Mach Punch" ]; var CStars = ["http://i281.photobucket.com/albums/kk208/masta_022/RiftRipper/customblock-1.gif","http://img167.imageshack.us/img167/77 9/type2forumstaryv9.png","http://i38.tinypic.com/2lj72p3.gif","http://img301.imageshack.us/img301/158/starfinalgh0.gif", " [url]http://i42.tinypic.com/2e22ow4.png[/url]","http://fc65.deviantart.com/fs40/f/2009/004/1/6/Proboards_star_by_Rain_of_Life.jpg"," [url]http://img237.imageshack.us/img237/130/toaststarts1.jpg[/url]","http://i33.tinypic.com/9joqio.gif","http://www.vulomedia.com/im ages/47806dark.png","http://i36.tinypic.com/15dsajr.gif","http://i43.tinypic.com/2vxipt1.gif", "http://img23.imageshack.us/img23/6020/stara.gif","http://i42.tinypic.com/20uzv5z.gif","http://i43.tinypic.com/2qv4h00.g if","http://i61.photobucket.com/albums/h79/Swearingworth/fire-star.png","http://i41.tinypic.com/v45q3m.jpg","http://i41. t inypic.com/2gy50g8.gif","http://a.random-image.net/memzak/reddice.jpg","http://i39.tinypic.com/25qakcy.gif","http://img4 . imageshack.us/img4/5147/rebelinsigniastar.png","http://i39.tinypic.com/264ia9y.gif","http://i41.tinypic.com/2edru3q.gif" , "http://i42.tinypic.com/2ak0guq.gif","http://upload.wikimedia.org/wikipedia/commons/4/4b/Empty.gif","http://i44.tinypic. c om/34yv97o.jpg","http://i39.tinypic.com/260bnfk.png","http://i40.tinypic.com/4r57gx.jpg","http://media.photobucket.com/i m age/one%20pixel%20transparent/alxz310/1-pixel-transparent.gif","http://i61.photobucket.com/albums/h79/Swearingworth/fire - star.png","http://i34.tinypic.com/xvw4l.gif","http://i33.tinyp ic.com/9joqio.gif","http://i36.tinypic.com/15dsajr.gif","http://i43.tinypic.com/20gzb5d.gif","http://i43.tinypic.com/2vx i pt1.gif","http://i151.photobucket.com/albums/s150/lournieads/mkzstar.png","http://i44.tinypic.com/2yjx5dc.gif","http://i304.photobucket.com/albums/nn194/xShadowLordx/shadowstar.gif", "http://i25.tinypic.com/2me6an6.gif", "http://i50.tinypic.com/eklpwh.jpg", "http://i259.photobucket.com/albums/hh298/Runescape_Dude/DuckStar.png", "http://img267.imageshack.us/img267/6671/stalkerwarningstar.png", "http://i35.tinypic.com/2ibhnkh.png","http://a.random-image.net/memzak/egg.jpg", "http://i412.photobucket.com/albums/pp204/izacque/Rollingstar.gif","http://img109.imageshack.us/img109/4057/vaconstar.gif","http://i41.tinypic.com/i5c67o.jpg","http://i41.tinypic.com/1zdb4si.png","http://img522.imageshack.us/img522/9015/star8c.png","http://img52.imageshack.us/img52/2056/machpunch.png"];
// Custom user stars, by MegaShadowChao. May not be duplicated, altered, or reposted except by the author. // var sregexp=/\{S=(\d+)\}/; var star=0; var tdlist=document.getElementsByTagName('td'); function DoStarSave(){ var ustar="{S="+mform.customstar.selectedIndex+"}"; mform.customtitle.maxLength+=ustar.length; mform.customtitle.value=ustar+mform.customtitle.value; } if(document.modifyForm){ if(document.modifyForm.customtitle){ var mform=document.modifyForm; mform.onsubmit=function(){disable(this); DoStarSave();} star=0; if(mform.customtitle.value.match(sregexp)){ star=RegExp.$1 } mform.customtitle.value=mform.customtitle.value.replace(sregexp,""); for(count=0; count<tdlist.length; count++){ if(tdlist[count].getElementsByTagName('td').length==0){ if(tdlist[count].innerHTML.match("Custom Title:")){ if(tdlist[count].width=="160"){ var stable=tdlist[count].parentNode.parentNode; for(count2=0;count2<stable.rows.length;count2++){ if(stable.rows[count2]==tdlist[count].parentNode){break;} } var srow=stable.insertRow(count2+1); var scol=srow.insertCell(0); scol.width="160"; scol.vAlign="top"; scol.innerHTML='<font size="2">Custom Star:</font>'; scol=srow.insertCell(1); scol.width="245"; scol.vAlign="top"; scol.innerHTML='<font size="2"><select name="customstar"><option>(none)</option></select></font>'; for(count2=0;count2<CStarNames.length;count2++){ var newop=document.createElement("option"); newop.innerHTML=CStarNames[count2]; mform.customstar.appendChild(newop); } mform.customstar.options[star].selected="1"; scol=srow.insertCell(2); scol.width="245"; scol.vAlign="top"; scol.innerHTML="<font size=\"1\">To have custom stars replace the standard ones under this user's name, choose the star group here.</font>"; break; } } } } } } else { for(count=0; count<tdlist.length; count++){ if(tdlist[count].width=="20%"){ if(tdlist[count].className.match("windowbg")){ if(tdlist[count].innerHTML.match(sregexp)){ star=RegExp.$1; tdlist[count].innerHTML=tdlist[count].innerHTML.replace(sregexp,""); for(count2=0;count2<tdlist[count].getElementsByTagName('img').length;count2++){ if(tdlist[count].getElementsByTagName('img')[count2].alt=="*"&&(!tdlist[count].getElementsByTagName('img')[count2].src.match(/warn/i))){ tdlist[count].getElementsByTagName('img')[count2].src=CStars[star-1]; } else { break; } } } } } } } </script>
|
|
|
Post by Fringe Pioneer on Jul 5, 2010 13:42:07 GMT
Fix implemented. Thank you.
The plain text is decieving: I'm actually very thankful, as our ignorance has kept us from our suffrage for over a year by now.
EDIT: However, it seems now that some people don't have stars when they should, and everyone has a square for custom titles even when they don't have a custom title. While I try to see if I can't find the problem myself, I would greatly appreciate it if you could find and fix the problem.
|
|
|
Post by disabled on Jul 5, 2010 17:00:38 GMT
As I already wrote on the Chat, the spaces added by the forum were the problem. I don't know if you got the url with the correct code, if not it is here.
|
|
|
Post by Fringe Pioneer on Jul 5, 2010 19:49:40 GMT
Thank you for helping to fix the problem and the resulting problems. As I have said on chat, I have removed the obsolete poll code...
|
|
|
Post by ~Memzak~ on Jul 20, 2010 16:07:27 GMT
Oh well. You can't ever make a code that needs absolutely no debugging... there will always be something... but I'm glad he fixed it... (unless the code you make is 1 - 10 lines long, in which case {most of the time} if there is a bug you are either a beginner or not trying at all)
|
|
|