HomeWildfire Games

Add Math.square to compute the square of a number without the need to repeat…

Description

Add Math.square to compute the square of a number without the need to repeat the term, without using the slower Math.pow.
Start unifying the euclidian distance functions instead of adding yet another helper function to the random map script library after this diff.

Differential Revision: https://code.wildfiregames.com/D969
Math.square accepted by mimo
Includes changes proposed by bb, fatherbushido

Event Timeline

(Correction, we already have the rmgen helper function)

mimo added a subscriber: mimo.Oct 23 2017, 8:48 AM

When did i accept this? i had comments (not important ones i agree) which were not taken into account and still does not think what has been implemented is the cleaner way to do it.
My answer to your pm saying that i'm fine with adding the math.square function is not an acceptation of the patch, and i think you are aware of that. So NEVER AGAIN do that: I understand people commiting patches without acceptation (that's sometimes needed, and i do that for the ai), but i can't accept to see my name added.

elexis added a comment.EditedOct 23 2017, 11:23 AM
In rP20328#23985, @mimo wrote:

My answer to your pm saying that i'm fine with adding the math.square function is not an acceptation of the patch

" Math.square accepted by mimo"

Where did I state that you accepted the patch?

(Also I did take your comments into account in the form of stating why I disagree with them. Notice that originally you disagreed with Math.square as well which is why I made that differential revision proposal to begin with)

mimo raised a concern with this commit.Oct 23 2017, 8:06 PM
In rP20328#23985, @mimo wrote:

My answer to your pm saying that i'm fine with adding the math.square function is not an acceptation of the patch

" Math.square accepted by mimo"

Where did I state that you accepted the patch?

I also never accepted Math.square, i only said in a pm that i was fine with it. For me, it only means i don't object or i don't care, but not that i support it as the commit message seems to imply. In fact here it was "i don't care", and certainly not something relevant to be put in a commit message of a patch i didn't look with attention. When you commit without formal acceptation in phabricator, you must assume your acts and not hide yourself by involving other people.

(Also I did take your comments into account in the form of stating why I disagree with them. Notice that originally you disagreed with Math.square as well which is why I made that differential revision proposal to begin with)

Once again, you distord what i said: i never objected to Math.square, i only said that it couldn't be faster than the direct multiplication. And as it happens that the difference is negligible, i don't care.

Then coming to the concern, i would have expected that you did some profiling before commiting it, which does not seem to be the case: i've tried this simple test inside the ai

Index: binaries/data/mods/public/simulation/ai/petra/_petrabot.js
===================================================================
--- binaries/data/mods/public/simulation/ai/petra/_petrabot.js  (révision 20330)
+++ binaries/data/mods/public/simulation/ai/petra/_petrabot.js  (copie de travail)
@@ -89,6 +89,25 @@
 
 m.PetraBot.prototype.OnUpdate = function(sharedScript)
 {
+       let x = [0, 0];
+       let y = [0, 0];
+       let time0 = Date.now();
+       for (let i = 0; i < 50000; ++i)
+       {
+               x[0] = i;
+               y[1] = i;
+               let dist = API3.SquareVectorDistance(x, y);
+       }
+       warn(" new time " + (Date.now() - time0));
+       time0 = Date.now();
+       for (let i = 0; i < 50000; ++i)
+       {
+               x[0] = i;
+               y[1] = i;
+               let dist = Math.square(x[1] - x[0]) + Math.square(y[1] - y[0]);
+       }
+       warn(" old time " + (Date.now() - time0));
+
        if (this.gameFinished)
                return;

and the result is
Turn 0 (200)...
Turn 1 (200)...

WARNING: new time 130 WARNING: old time 5 WARNING: new time 135 WARNING: old time 0 WARNING: new time 133 WARNING: old time 0 WARNING: new time 128 WARNING: old time 1

nice for a patch supposed to improve performances. I've never counted the number of distance calls by the ai every turns, but i think it could reach several ten thousands on turns with building placement (and maybe even more on large maps). In fact, i suppose this factory lag you've added is because of the spread operator ... that you've put in the ai function.

Then on a less important side, why calling the function euclidDistance and not distance? that's just pedantic, gives the impression for anybody not used to maths that it does something complicated and doubles the number of characters needed with no reason.

This commit now has outstanding concerns.Oct 23 2017, 8:06 PM
In rP20328#24020, @mimo wrote:

I also never accepted Math.square, i only said in a pm that i was fine with it.

That sounds exactly equivalent to me.

For me, it only means i don't object or i don't care

"acceptance is person's assent to the reality of a situation, recognizing a process without attempting to change it or protest it." according to wikipedia.
If you don't care, say so instead of saying that you're ok with things.

certainly not something relevant to be put in a commit message

The sole reason why I have stated that you accepted Math.square in the commit message and created a proposal to begin with was to establish whether
you object the introduction of the functions following the impression I got from https://code.wildfiregames.com/rP20263#23668

not hide yourself by involving other people.

The commit message exactly states the results of the discussions of the patch.
Nowhere did I state that anyone accepted the patch like I did with every patch that got reviewed.

originally you disagreed with Math.square
Once again, you distord what i said

I (apparently falsely) suspected that https://code.wildfiregames.com/rP20263#23668 meant disagreement of adding the functions, which is why I asked again before adding them.

The test compares the changed function with an inlined call, but it should compare the prior function with the new function.
But I can confirm that the variant with the spread operator in this case is 300 times slower.
This means a distance computation consumes about 1-2 microseconds. Sounds relevant as thousands of them can occur on a turn.

After removing the spread operator, the before/after times still differ about 15%.
However since a function call then consumes about 0,008 microseconds on my machine, I would assume that is irrelevant.
If it is considered relevant then the API function could be removed too, because the performance would differ by 12% furthermore if the API call would be replaced with the formula everywhere.

nice for a patch supposed to improve performances

This euclid distance diff was a duplication removal patch.

Then on a less important side, why calling the function euclidDistance and not distance? that's just pedantic

There are many distance measures https://en.wikipedia.org/wiki/Category:Similarity_and_distance_measures
If a function exactly states what it does, the reader doesn't have to look it up to determine it's behavior.

mimo added a comment.Oct 24 2017, 9:06 AM
In rP20328#24020, @mimo wrote:

I also never accepted Math.square, i only said in a pm that i was fine with it.

That sounds exactly equivalent to me.

For me, it only means i don't object or i don't care

"acceptance is person's assent to the reality of a situation, recognizing a process without attempting to change it or protest it." according to wikipedia.
If you don't care, say so instead of saying that you're ok with things.

certainly not something relevant to be put in a commit message

The sole reason why I have stated that you accepted Math.square in the commit message and created a proposal to begin with was to establish whether
you object the introduction of the functions following the impression I got from https://code.wildfiregames.com/rP20263#23668

not hide yourself by involving other people.

The commit message exactly states the results of the discussions of the patch.
Nowhere did I state that anyone accepted the patch like I did with every patch that got reviewed.

Unfortunately, you are still lying. I put back my own words "i don't see any drawbacks to have it" in answer to the pm you sneakily send me to ask my advice, never mentionning that this will be taken as a formal acceptation for a commit. From somebody who has some ethics, i would have expected at worse some regrets, and at best excuses, for having used improperly my name. It seems that's something completely alien to you. That's a behaviour i would never accept in real live, so i won't accept it here.

originally you disagreed with Math.square
Once again, you distord what i said

I (apparently falsely) suspected that https://code.wildfiregames.com/rP20263#23668 meant disagreement of adding the functions, which is why I asked again before adding them.

The test compares the changed function with an inlined call, but it should compare the prior function with the new function.

completely irrelevant and stupid argument (that cannot explain factor 100 difference) to once again try to hide the problem you created.

But I can confirm that the variant with the spread operator in this case is 300 times slower.

Ah at last!

This means a distance computation consumes about 1-2 microseconds. Sounds relevant as thousands of them can occur on a turn.

After removing the spread operator, the before/after times still differ about 15%.
However since a function call then consumes about 0,008 microseconds on my machine, I would assume that is irrelevant.
If it is considered relevant then the API function could be removed too, because the performance would differ by 12% furthermore if the API call would be replaced with the formula everywhere.

nice for a patch supposed to improve performances

This euclid distance diff was a duplication removal patch.

Then on a less important side, why calling the function euclidDistance and not distance? that's just pedantic

There are many distance measures https://en.wikipedia.org/wiki/Category:Similarity_and_distance_measures
If a function exactly states what it does, the reader doesn't have to look it up to determine it's behavior.

That's the exact point. How many people knows what a euclidian distance is? while everybody knows what a distance is. And once again, the argument of lot of distances in wikipedia is just stupid. It is only when we use a term in a meaning different from the usual one that we have to describe it in the name.

According to my understanding of language, "Math.square accepted by someone" exactly means that that the person stated being fine with the introduction of a Math.square function, i.e. this part of the diff:

/**
 * Get the square of a number without repeating the value and without calling the slower Math.pow.
 */
Math.square = function(x)
{
	return x * x;
};

I won't participate in taking this dispute a personal level.
I will never state your name in a commit message unless you added a green checkmark, which hopefully fulfils your request.

mimo added a comment.Oct 24 2017, 6:57 PM

According to my understanding of language, "Math.square accepted by someone" exactly means that that the person stated being fine with the introduction of a Math.square function, i.e. this part of the diff:

Nonsense, "accepted" put in a commit message means much more than "i don't see any drawback".

I won't participate in taking this dispute a personal level.
I will never state your name in a commit message unless you added a green checkmark, which hopefully fulfils your request.

It is me who didn't ask anything, but you sent me the pm without giving the exact context of why you asked me that question and then quoted wrongly my answer on something i didn't want to be involved with. So i'm still waiting for some excuses.

elexis added a comment.EditedOct 24 2017, 8:10 PM

" I'm also ok with EuclidDistance functions."
What does "also ok" mean?

What does "Math.square accepted by mimo" mean to you?

mimo added a comment.Oct 24 2017, 8:40 PM

That is becoming completely crazy, and i start to believe you are completely stupid (sorry for the personnal aspect).

You asked me "Would you be ok with me implementing these functions in D969 ?". I don't see how i could answer anything except yes to such a generic question. And i answered that in a very loose way (I don't see any drawback for the first, and also ok for the second).

"Accepted" in a commit message means i support the way it is implemented (which i never said and i really hate when people make me say things i don't think).

These are two different things, and i really find sneaky the way you behaved and still are behaving.

bb added a subscriber: bb.Oct 24 2017, 9:00 PM
In rP20328#24047, @mimo wrote:

That is becoming completely crazy

That is exactly what happens here, the point seem rather clear: both of you value the same words differently. In which neither interpretation is wrong/lesser/better or whatever than the other. Mimo is right when he says he didn't meant to say the patch was ready for commit and nor he clearly set it was. Elexis interpreted that it was, which is a valueable interpretation of "having no drawback". However you are making a flame-ware from it and that won't help the situation. So can both agree on trying to be 1) more clear in what you say 2) less over-interpretative? (How hard both things even can be.)

In rP20328#24047, @mimo wrote:

"Accepted" in a commit message means i support the way it is implemented which i never said

You stated in the PM that you are ok with the function definition:

Math.square would just multiply the two numbers, right? then i don't see any drawbacks to have it (i hope the compiler would inline it). I'm also ok with EuclidDistance functions.

When I stated Math.square accepted by mimo I merely meant the function definition not the calls to it. I regret the ambiguity of that sentence which I did not foresee.

Imarok added a subscriber: Imarok.Oct 24 2017, 10:16 PM

Can we just stop this discussion?
elexis committed the thing and mimo tolerates it.
The commit may be wrong or may be not, but as we can't change that, it doesn't matter anymore.

elexis requested verification of this commit.Oct 26 2017, 3:02 PM

Spread operator slowness fixed by rP20351.
As mentioned above, calling the Math function from the utils.js function still makes a difference of 12% and calling the utils function in comparison to doing the computation in each of the 90 calls would also make a difference of 15% according to the test at that time (which is irrelevant in comparison to the factor of 200, but might or might not be considered relevant independent of the comparison.)

This commit now requires verification by auditors.Oct 26 2017, 3:02 PM
elexis removed an auditor: mimo.Nov 3 2017, 8:16 PM
This commit no longer requires audit.Nov 3 2017, 8:16 PM