New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GM 3.5beta1+: GM_getResourceText seems slow #2346
Comments
It would probably be more efficient to load the style from the resource URL instead of adding it as text. GM_addStyle does nothing more than just injecting a |
Ad GM_addStyle: However, it has nothing to do with it... After returning lines: The file loads slowly - any file... |
AFAIK: This line does not make sense (this condition will never be fulfilled): ...if nothing changes, e.g.: From: return GM_util.fileXhr(dep.file_url, "text/plain"); To: dep.textContent = GM_util.fileXhr(dep.file_url, "text/plain");
return dep.textContent; But this does not solve the original problem... (only after the second load) |
That's intentional to reduce memory footprint. resource files can be very large, reading them into memory and sending them to the child process would be a huge waste if they are not used in text form or only loaded via URL. Basically, the encouraged way is to load them via URL, not via text string.
It does. The problem with it is that it takes a string and not a URL. Using the URL directly should be faster. With a URL FF can pass down the file contents efficiently (shared memory) instead of copying javascript strings.
Yeah, it was kinda meant as backwards compatibility so a parent process |
I understand why it was done. But... Allocation of memory ≠ memory leaks. Accessing data from disk is slow (in this case, no cache is made). |
I think the user can simply adjust his script by using |
Hi, I wrote the email that initiated this issue. That still begs the question, no matter what the resource is a 100ms+ access time seems like a huge penalty to use the @resource feature. Is this really the intended operation of the @resource? |
If this is a response to my suggestion of using GM_getResourceURL, have you read its documentation? |
I read the documentation, but it wasn't clear to me as to how it would help or exactly what it did. This was partially because there was a bunch of conflicting explanations on the web referencing older greasemonkey versions. After I understood a little more about how it worked, I altered the script to use GM_getResourceURL and it mostly alleviated the issue in Firefox. The css files loaded quickly, but the resulting web page wasn't identical. That part is probably the result of some css precedence conflicts that I'll have to track down myself. I know it's not the place to bring up problems with Tampermonkey, but unfortunately (for me) this solution isn't cross platform compatible.(unless I'm doing something wrong, which is quite likely) for firefox I did this:
for tampermonkey I did this and it worked:
After I looked at the tampermonkey solution a bit further it doesn't even make sense given the full encoded text ends up in the href, but it does work for some reason. Is there something simple I'm missing that would make it cross platform? That still leaves a dangling question. What is the intended use of GM_getResourceText with access times being so slow? Is the GM_getResourceURL meant to replace this most of the time? |
For those times where you really want manipulate the string instead of just putting it somewhere in the DOM. The sad state of things is that the API is synchronous and providing potentially very large chunks of data in a synchronous manner either eats memory or is slow. Maybe we should deprecate it and instead allow
whenever possible, yes.
well, what does TM do? |
Tampermonkey exhibits the old behavior of GM_getResourceURL. It gives you the full base64 representation of the the css file, not just a local url. |
Then it shouldn't really need special treatment. TM will load it as data URI, GM will load it through its custom uri scheme. Maybe you have to explicitly specify the |
TM returns a base64 encoded string instead of a real dataURI here (see Tampermonkey/tampermonkey#254). This issue will be fixed soon. Sorry for any inconvenience. |
This bug is either not valid, or is only valid in some specific context and needs more detail. I wrote a test script: https://gist.github.com/arantius/2e385ac853260c4e6612 It takes an arbitrary
It takes ~1.5ms, not 100ms, to call Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0 If you disagree, please run the exact script linked, and paste both the log and the "User Agent" line from the about:support page. |
Ups, I'm sorry. |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0 I ran the linked test script and came up with better times for large N
but with N=1
This total time ranged from 190ms ~ 460ms across many separate refreshes of a test page where N=1. The best solution thus far solution to my original problem is likely the slightly less intuitive |
With N=1 I see e.g.
More variance, rarely up to 13ms, but still nowhere close to 100. Your user agent shows Windows. Maybe Windows is doing something unusual here. I'll have to remember to try to test this when I'm near a Windows box to help confirm. Only have Linux and Mac nearby at the moment. |
Minor update. I've confirmed the slow behavior on two more Win7 installs. |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0 Ad https://gist.github.com/arantius/2e385ac853260c4e6612: before 2016-01-21T14:41:43.884Z With N=1: With N=2: |
@janekptacijarabaci are you sure that's correct? With N=1 there's no way for the mean time per call to be 1.274ms when the total time is 637ms With N=1: With N=2: |
I'm sorry. N = 500 "N=1" = running second time "N=2" = running third time N=1: Running first time Running second time |
janekptacijarabaci, whats your CPU? try to uninstall antivirus. all tests with N=1: intel sandy bridge, 1.6GHz, 1 core, win7 x64:
intel sandy bridge, 3.4GHz, 4 cores, win7 x64:
intel sandy bridge, 1.6GHz, 4 cores, win7 x64:
may be with intel atom 100ms is "normal" for FF44 & GM 3.6? or with stupid antivirus. |
In a post-e10s world, stuck with this old synchronous API, in order to service a There's a lot of things going on here. On any one machine any one of those steps could be slow for any number of reasons. * Perhaps memoizing this could help? I've updated the measurement script to v2. Now I get e.g.
Which is still pretty reasonable, though I do see the occasional slowish (~60ms above) call. By manually inspecting the raw samples, I can see that (for me) the worst case is about
Because the slow calls all seem to be bunched at the front; after ~10 they're all ~1ms each. A mean of 50ms is indeed "slow". This was an outlier though, usually I'm max/mean in the 60/15 range. Accounting for where that time goes will not be easy, but is something to pursue. |
are you sure you have the right bug? this is about resources, not get/set value |
Oh foolish me! Above I was describing For the latter we're doing the fileXhr thing, which all works in the child process. (For now.) And I have even less idea what to do about being faster. |
I think the only real solution is to offer an async API. It would not make individual calls faster, but it would allow multiple of them to be performed / awaited in parallel. Maybe just add an argument and if it is present then return a promise instead of the string? Consuming code can be backwards-compatible by type-checking the returned object and wrapping it in a promise if it's a string and then use the same code path. |
WebExtensions will be available soon. They have async API and they are easy to create. |
Ad https://groups.google.com/forum/#!topic/greasemonkey-users/o504w12bu6Y
Confirmed on:
GM 3.5beta1+
Not confirmed on:
GM 3.4.1-
See 6fe96d6#diff-4b4ab9adda07ca484ef0efbd20401182L28
@the8472
What is the best solution to fix this problem?
The text was updated successfully, but these errors were encountered: