Page MenuHomeWildfire Games

Microsecond-precise JS performance measurement
ClosedPublic

Authored by elexis on Mar 5 2017, 7:25 AM.

Details

Summary

Often we had been discussing which code is faster in JS, in particular in the GUI when calling GetEntityState functions.
But we often couldn't do actual measurements as JS only has millisecond precise timestamps.
Looping over the tested code helps, but getting an actual microsecond timestamp is preferable.
SpiderMonkey comes with a function doing that and it were nice to expose it through the Engine object accessible in the GUI.

This could also be added to the AI Engine object if needed.

Test Plan

Read https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/JSAPI_reference/JS_Now
Make sure that it compiles.
Measure some GetEntityState calls.

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

elexis created this revision.Mar 5 2017, 7:25 AM
Vulcan added a subscriber: Vulcan.Mar 5 2017, 8:15 AM

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (302 tests)..............................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (302 tests)..............................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/467/ for more details.

echotangoecho added a subscriber: echotangoecho.

If we change the function to return a double instead of an i64, this works well.

The double our tests require is capped by 2^53, so using this for a timestamp should work for the next 285 million years.
Using i64 would be great, but since the JS Number type can't encode numbers greater than 2^53 (only JS number type) and since it was removed due to being plain wrong D205 / rP19367, we will have to use this double thing again indeed!

elexis updated this revision to Diff 1509.Apr 28 2017, 4:33 PM

Use double since i64 is not going to be used.

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/904/ for more details.

vladislavbelov accepted this revision.Apr 28 2017, 5:33 PM
vladislavbelov added a subscriber: vladislavbelov.

Just call it "GetMicroseconds", then it's ok.

This revision is now accepted and ready to land.Apr 28 2017, 5:33 PM
leper added inline comments.
source/gui/scripting/ScriptFunctions.cpp
979 ↗(On Diff #1509)

.. the epoch.

1114 ↗(On Diff #1509)

Why not keep the order at least similar to the rest of the register calls? (So put this below the Start/Stop functions.)

elexis marked 2 inline comments as done.Apr 29 2017, 2:28 AM
elexis added inline comments.
source/gui/scripting/ScriptFunctions.cpp
979 ↗(On Diff #1509)

I guess we don't need to state that it's a unix timestamp again since the other Notable_epoch_dates_in_computing are too unlikely and in doubt, people can still lookup the documentation of that function. Still not bad to have it mentioned explicitly IMO when already adding a comment.

Also using doxygen style.

1114 ↗(On Diff #1509)

Ah, thanks

elexis marked 2 inline comments as done.Apr 29 2017, 2:35 AM

My computation was wrong.

2^53 microseconds = 9,007199255×10^9 seconds = year 2255!

Perhaps we will have better a JS Number type by then?

elexis updated this revision to Diff 1520.Apr 29 2017, 2:37 AM

doxygen comment, remove 1970 comment, correct sort order

vladislavbelov accepted this revision.Apr 29 2017, 2:41 AM

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/914/ for more details.

Build is green

Updating workspaces.
Build (release)...
Build (debug)...
Running release tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!
Running debug tests...
Running cxxtest tests (306 tests)..................................................................................................................................................................................................................................................................................................................OK!

http://jw:8080/job/phabricator/915/ for more details.

echotangoecho accepted this revision.May 10 2017, 7:33 PM
This revision was automatically updated to reflect the committed changes.