Are google servers powerful?

59 views
Skip to first unread message

ChiefChippy2 is awesome

unread,
Mar 31, 2019, 1:40:12 PM3/31/19
to Google Apps Script Community
I feel like Google Apps Script Server side code runs quite slow.
I have a pure JS calculator that can calculate any multiplications ( even up to lots of digits ) as well as exponents ( powers ).
I tried to calculate 999^99 :
On GAS it took about 7 secs (6945 ms)
On my PC ( which is fairly powerful ) it only took less than a sec, 279ms.
Both answers are the same ( although i didn't verify if they were correct )

I am wondering : are Google Apps Script Servers not as powerful as one would expect or is it just my PC that is very powerful?

Dimu Designs

unread,
Mar 31, 2019, 3:07:02 PM3/31/19
to google-apps-sc...@googlegroups.com
The calculation of that expression probably took about the same time on Google's machines as it did locally on your machine. 

What you did not factor into your calculations is latency - the time it takes for your request to reach google's servers and for the response to be returned to your client browser. 

Latency can vary widely depending on your location relative to the google servers available in your region. 

But in all fairness, the current implementation of Apps Script is based on Rhino, an old javascript engine. With the upcoming V8 engine upgrade App Script is expected to execute up to 10 times faster as stated in 2017's Google Next announcement. 

I strongly suspect that these upgrades would have already been rolled out were it not for the EU's new GDPR rules. Now Google has to go over all their offerings with a fine-toothed comb to ensure they are in compliance with those laws (otherwise they might get slapped with another US$50 million fine!), likely pushing back the release date of the upgrade.

ChiefChippy2 is awesome

unread,
Mar 31, 2019, 4:30:18 PM3/31/19
to Google Apps Script Community
Yeah, that might be the reason.... although the timing is also executed there though... (it is in the same function )

I live in EU but I am near the data centers available in Europe. (Not too far at least, I mean 6.5 secs of latency is quite huge ).

Anyway I really hope they would upgrade the engine to V8.

On Sunday, March 31, 2019 at 9:07:02 PM UTC+2, Dimu Designs wrote:
The calculation of that expression probably took about the same time on Google's machines as it did locally on your machine. 

What you did not factor into your calculations is latency - the time it takes for your request to reach google's servers and for the response to be returned to your client browser. 

Latency can vary widely depending on your location relative to the google servers available in your region. 

But in all fairness, the current implementation of Apps Script is based on Rhino, an old javascript engine. With the upcoming V8 engine upgrade App Script is expected to execute up to 20 times faster as stated in 2017's Google I/O announcement. 

Riël Notermans

unread,
Apr 1, 2019, 4:17:13 AM4/1/19
to Google Apps Script Community
This upgrade and a 10x speed improvement is planned for this year.

Riël Notermans

Op woensdagen vrij • Zzapps B.V. • High Tech Campus 9, 5656 AE Eindhoven • T 040 711 41 94 • E ri...@zzapps.nl • www.zzapps.nl
WIJ MAKEN HET ONDENKBARE MOGELIJK


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-script-community.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/dc041121-ff39-46df-9642-7884b0b3f062%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joe Schmidt

unread,
Apr 1, 2019, 8:48:04 AM4/1/19
to Google Apps Script Community
I suspect that a script is interruptive like Basic on a Commodore 64 for you older folks.  That means that it has to figure out what each line of the script must do every time the line is processed.  I also suspect that the compute engine for a spreadsheet is written in machine language which runs much faster.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

Dimu Designs

unread,
Apr 1, 2019, 8:51:30 AM4/1/19
to google-apps-sc...@googlegroups.com
Decided to run a test within the Apps Script GUI editor using the following script:

function speedTest() {
    var before,
        after,
        
        result;
    
    before = Date.getNow();
    result = Math.pow(999, 99);
    after = Date.getNow();
    
    Logger.log("Result = %s", result.toFixed());
    Logger.log("Before = %sms, After = %sms", before.toFixed(), after.toFixed());
    Logger.log("Time elapsed = %sms", (after - before));
}


And I got the following results:

speedTestResults.png


Seems like Apps Script processed the calculation in less than a millisecond on Google's server...

ChiefChippy2 is awesome

unread,
Apr 1, 2019, 11:03:32 AM4/1/19
to Google Apps Script Community
Yes, but Math.pow() is a built-in function.
I did absolutely the same thing you did, the only difference is that instead of Math.pow("999","99") I put the custom function I made ( as a library ).
(Of course math.pow should be instant or there would be issues )

Bruce Mcpherson

unread,
Apr 1, 2019, 11:18:46 AM4/1/19
to google-apps-sc...@googlegroups.com
I had a look into this a while ago, and indeed Apps Script is not running on a modern engine like you have in your browser.
see here for write up.

So you have javascript being interpreted by Java (which is semi compiled) on a shared server with a variable workload. JavaScript in your browser will generally be faster, but if you are using google APIS from apps script, it avoids the need to bring data back to your local client to be processed.

When the engine upgrades to V8, we all expect to see some big improvements.

bruce



--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

Dimu Designs

unread,
Apr 1, 2019, 11:23:12 AM4/1/19
to Google Apps Script Community
If you are referencing a library (via Resources > Libraries ) then that could be why your script is so slow. Google actually discourages developers from using them in their add-ons, stating that excessive use of libraries will slow down their applications...

Bruce Mcpherson

unread,
Apr 1, 2019, 11:53:26 AM4/1/19
to google-apps-sc...@googlegroups.com
Google do say that (and there are plenty of maintainability reasons to not use libraries), but i did some extensive testing on this a while back and didn't find any measurable penalty,


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-script-community.

Riël Notermans

unread,
Apr 1, 2019, 12:22:16 PM4/1/19
to Google Apps Script Community
I am interested in that Math.pow custom code then...

Op ma 1 apr. 2019 17:53 schreef Bruce Mcpherson <br...@mcpher.com>:

ChiefChippy2 is awesome

unread,
Apr 1, 2019, 2:58:19 PM4/1/19
to Google Apps Script Community
It is basically a very un-efficient way of doing powers ( I couldn't think of ways to improve it directly ), by doing the calculations like a human.
999^99 would be doing 999*999 98 times, and the multiplication involves a humanlike process : to calculate 123*456 it would do 123*4 + 123*5*10 +123*6*100, which would further develop to 3*4+2*4*10+1*4*10+...
That is basically the idea written in JS, although it should always give correct answers ( I tested with tricky calculations most calculators fail, such as 111111111111111111111111111*2 which should be quite easy for a human )

Edward Ulle

unread,
Apr 1, 2019, 3:23:24 PM4/1/19
to Google Apps Script Community
I may be dating myself but I used to do calculation on a slide rule.  I'd get the first few digits and the power and that was about all anyone needed.  Your example 111111111111111111111111111*2 would be 2.22X10^26 since worrying about any more digits might be a waste of time.  And to do this calculation mentally or on slide rule would take seconds because mentally I have to count the number of 1's to figure out how many 2's there are.  So rather than figure out how I would do tedious or complicated math I look for a library or use the built in functions to do it for me, where someone has figured it out and optimized it.
Reply all
Reply to author
Forward
0 new messages