[issue14381] Intern certain integral floats for memory savings and performance

2012-04-20 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: Because pfval in this example doesn't exist but is merely a temporary, there is no aliasing. Maybe aliasing wasn't the right word to use, then. The exact rule being violated is C99 6.5, para. 7 (or C11 6.5 para. 7 if you prefer): An

[issue14381] Intern certain integral floats for memory savings and performance

2012-04-20 Thread Kristján Valur Jónsson
Kristján Valur Jónsson krist...@ccpgames.com added the comment: Interesting. I declare that this rule does not apply here since the code is a deliberate hack: We are pretending that a certain address points to integers and checking those integers. If you insist on following the standard,

[issue14381] Intern certain integral floats for memory savings and performance

2012-04-20 Thread Kristján Valur Jónsson
Changes by Kristján Valur Jónsson krist...@ccpgames.com: -- Removed message: http://bugs.python.org/msg158808 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14381 ___

[issue14381] Intern certain integral floats for memory savings and performance

2012-04-20 Thread Kristján Valur Jónsson
Kristján Valur Jónsson krist...@ccpgames.com added the comment: Interesting. I declare that this rule does not apply here since the code is a deliberate hack: We are pretending that a certain address points to integers and checking those integers. If you insist on following the standard,

[issue14381] Intern certain integral floats for memory savings and performance

2012-04-20 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: I declare that this rule does not apply here ... Clearly the gcc developers disagree. :-) iwasawa:~ mdickinson$ cat test2.c int is_positive_zero(double f) { return *(long long*)f == 0; } iwasawa:~ mdickinson$ gcc -fstrict-aliasing -O3

[issue14381] Intern certain integral floats for memory savings and performance

2012-04-20 Thread Kristján Valur Jónsson
Kristján Valur Jónsson krist...@ccpgames.com added the comment: Dang. I yield! -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14381 ___ ___

[issue14381] Intern certain integral floats for memory savings and performance

2012-04-19 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: Why do you think it isn't safe, Antoine? It violates C's strict aliasing rules; Google for 'C strict aliasing' or 'C type punning' for more information. This isn't just a theoretical concern: gcc is known to make optimizations based on

[issue14381] Intern certain integral floats for memory savings and performance

2012-04-19 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: We only support IEEE platforms. I don't think that's true, BTW. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14381 ___

[issue14381] Intern certain integral floats for memory savings and performance

2012-04-19 Thread Kristján Valur Jónsson
Kristján Valur Jónsson krist...@ccpgames.com added the comment: return *(PY_LONG_LONG*)fval == 0; There is no aliasing, because there are no pointer variables in existence. If we did this: double *pfval = fval; PY_LONG_LONG *pl = (PY_LONG_LONG*)pfval return *pfval == 0 Then we would have

[issue14381] Intern certain integral floats for memory savings and performance

2012-04-18 Thread Jesús Cea Avión
Changes by Jesús Cea Avión j...@jcea.es: -- nosy: +jcea ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14381 ___ ___ Python-bugs-list mailing list

[issue14381] Intern certain integral floats for memory savings and performance

2012-03-26 Thread Kristján Valur Jónsson
Kristján Valur Jónsson krist...@ccpgames.com added the comment: Why do you think it isn't safe, Antoine? We only support IEEE platforms, and IEEE defines positive 0.0 to be all bits cleared. I personally don't think that even a small measurable performance degradation in creating new floats

[issue14381] Intern certain integral floats for memory savings and performance

2012-03-26 Thread Eric Snow
Changes by Eric Snow ericsnowcurren...@gmail.com: -- nosy: +eric.snow ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14381 ___ ___ Python-bugs-list

[issue14381] Intern certain integral floats for memory savings and performance

2012-03-23 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: PyBench contains a lot of different tests and executes them not too long. Random fluctuations of a few percent are possible. We need a more stable realistic test working with floats. $ ./python -m timeit 'x,y,d=1,0,0.01 for i in

[issue14381] Intern certain integral floats for memory savings and performance

2012-03-23 Thread Raymond Hettinger
Raymond Hettinger raymond.hettin...@gmail.com added the comment: FWIW, I'm -1 on making the change. Any memory savings would be microscopic for most Python programs. And anything that slows down float creation (even a teeny bit) is detrimental to all Python programs. We're better off not

[issue14381] Intern certain integral floats for memory savings and performance

2012-03-22 Thread Kristján Valur Jónsson
Kristján Valur Jónsson krist...@ccpgames.com added the comment: Yes, there is a measurable performance decrease in pybench arithmetic tests. Integers don't fall out of arithmetic that often, true. But integral floats are incredibly common in tabular data. In a game such as Eve Online,

[issue14381] Intern certain integral floats for memory savings and performance

2012-03-22 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: Integers don't fall out of arithmetic that often, true. But integral floats are incredibly common in tabular data. In a game such as Eve Online, configuration data contains a lot of 0.0, 1.0, -1.0 and so on. This patch saved us many

[issue14381] Intern certain integral floats for memory savings and performance

2012-03-22 Thread Kristján Valur Jónsson
Kristján Valur Jónsson krist...@ccpgames.com added the comment: The -10..11 range was determined empirically. As you see from the values, only -10 shows up as significant... In fact, just storing 0 to 5 would capture the bulk of the savings. Right, I'll do some test with the hardcoded

[issue14381] Intern certain integral floats for memory savings and performance

2012-03-22 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: Right, I'll do some test with the hardcoded values you mentioned. Btw, I don't think -0.0 is worth it, that value is a typical arithmetic result and not something you typically get from input data. I was suggesting -0.0 in the hope that it

[issue14381] Intern certain integral floats for memory savings and performance

2012-03-22 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: Try moving your changes from PyFloat_FromDouble to PyFloat_FromString. Look at memory and perfomance. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14381

[issue14381] Intern certain integral floats for memory savings and performance

2012-03-22 Thread Kristján Valur Jónsson
Kristján Valur Jónsson krist...@ccpgames.com added the comment: PyFloat_FromString() is very restrictive. In our case, for example, the floats in question don't come from text files. I'm adding a new file with changes suggested by Antoine. only 0.0 and 1.0 are interned. It turns out that

[issue14381] Intern certain integral floats for memory savings and performance

2012-03-22 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: Ok. In the current state it doesn't look detrimental, although I'm not convinced it's that useful either. That said, the implementation needs a bit of work, I don't think it's ok for float_is_positive_zero() to use the Py_LONG_LONG casting

[issue14381] Intern certain integral floats for memory savings and performance

2012-03-21 Thread Kristján Valur Jónsson
New submission from Kristján Valur Jónsson krist...@ccpgames.com: Michael Foord reminded me of this issue recently. It was discussed on pydev a few years back and met with limited enthusiasm. I speak from experience in live production with EVE that this simple change saved us a lot of

[issue14381] Intern certain integral floats for memory savings and performance

2012-03-21 Thread Serhiy Storchaka
Serhiy Storchaka storch...@gmail.com added the comment: Does it not decrease the performance? Falling out integral floating point numbers in the mathematical floating point calculations seems unlikely. I suggest interning integral floats only in conversions str - float and int - float.

[issue14381] Intern certain integral floats for memory savings and performance

2012-03-21 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: This looks like a duplicate of issue 4024. -- nosy: +mark.dickinson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue14381 ___