amshove / GC_little_helper

GC little helper
GNU General Public License v2.0
35 stars 22 forks source link

Slow loading #39

Closed dagger38 closed 10 years ago

dagger38 commented 10 years ago

when i load a cache pagina , it take's several minutes to complete... I disabled loading the logs with gc little helper , it helps a little.

I always get the "firefox is not reacting" report , and after a wile things get going.

Than when i scroll down it scrolls a little , firefox freezes , and moves , freezes...

Something wrong with GC Little helper? or with the greasemonkey...

It started with 10.6

dagger

D-Jakke commented 10 years ago

Same story here Slow loads and freezes :(

dagger38 commented 10 years ago

Beginning to think it has somthing to do with Firefox! Google images = slow No problems with chrome but there greasemonkey don't run...

Torsten- commented 10 years ago

Is this problem still present? Have you figured out, if it is a FF, Greasemonkey or GClh problem?

rattenburg commented 10 years ago

Hi Torsten, the problem still persists on FF:

Whenever a GC website is loading, FF freezes several seconds. Then, the changes of GCLH become visible, but FF freezes again for several seconds. After that, everything works fine ... until another page is processed by GCLH.

The problem still persists when disabling all addons (except GM) and all other GM scripts. There is no freeze when only GCLH is disabled. But that's not an option of course! ;-)

I'm facing the problem on 2 computers running Windows and 1 running Linux (each with the latest FF, GM, and GCLH). I've also heard of a friend with the same issue.

I further tried to do some simple debugging. It seems that the GCLH script is run twice when loading a page. The problem did not occur with Chrome.

rattenburg commented 10 years ago

Hi again,

the problem still persists and is very annoying. Hence, I did some debugging/profiling and spotted the cause: The function getValue(..) is slow!

It turned out that between lines 305 and 473 (where settings are loaded), GCLH needs 2 or more seconds! Further, since the script somehow runs twice, this sums up to more than 4 seconds.

A quick fix seams to be to comment out line 301: //GM_setValue( "gclhConfigKeys", JSON.stringify(gclhConfigKeys) ); Then, a run of GCLH takes about half a second, which improves the freezing time by a factor of 4.

I think that the GM-function GM_getValue(..) is also quite slow. However, it seams to me that the whole problem was introduced with the variable gclhConfigKeys for synchronization of settings!!

rattenburg commented 10 years ago

I've written a workaround that basically stores all settings in a single variable (via JSON). By this, only this single variable is read during loading. The adapted script runs in 50ms rather than 2000ms!

var CONFIG = JSON.parse(GM_getValue( "CONFIG", '{}' ));

function setValue( name, value ){
    GM_setValue( name, CONFIG[name] = value );
    GM_setValue( "CONFIG", JSON.stringify(CONFIG) );
}

function getValue( name, defaultValue ){
    if(CONFIG[name] === undefined) {
        CONFIG[name] = GM_getValue( name, defaultValue); 
        GM_setValue( "CONFIG", JSON.stringify(CONFIG) );
    }
    return CONFIG[name];
}
Torsten- commented 10 years ago

Hi rattenburg,

I've implemented your changes. Can you test ist? https://github.com/amshove/GC_little_helper/raw/saveAllToOneElement/gc_little_helper.user.js

There are some users telling that this doesn't help (via mail and forum: http://forum.geoclub.de/viewtopic.php?f=117&t=46168&sid=08348634c813163d61cb88a66e408a29&p=1161147#p1161147)

Regards Torsten

rattenburg commented 10 years ago

Hi again,

thanks for implementing the all-in-one-value-settings. But it is still slow indeed. This is because on each call of getValue, also the function GM_setValue("CONFIG",JSON.stringify(CONFIG)); is called in line 311. It works like a charm if you comment this out!

Tomorrow, I can try to improve this by understanding the variable gclhConfigKeys ...

rattenburg commented 10 years ago

I sent a pull request which fixes the problem.

lukeIam commented 10 years ago

https://github.com/amshove/GC_little_helper/commits/saveAllToOneElement