[Python-ideas] Re: inline Python functions and methods

2021-12-10 Thread TobiasHT
So I went back and revised my idea for inline functions in python, and I 
realized that it would be harder to implement them in python the way I had 
originally thought about them, due to Python’s dynamic nature. However, the 
idea itself doesn’t seem so original, as Cinder already implements inline 
byte-code caching which significantly boosts its performance. I do not think 
they ever upstreamed these changes however.

So a modification of my idea goes like this. The inline functions can still be 
written with the inline keyword, but evaluated at runtime. This is because 
there are some cases such as in conditions where are function might never be 
called at all, so it wouldn’t need to be optimized in that case
so in cases where someone writes code like,

if True:
inline def func_version_one(*args):
#func body
pass
else:
inline def func_version_two(*args):
#func body
pass

The right function to perform inlining on shall be determined at runtime and 
cached in the same scope as where it’s performing it’s operations from cases 
where the program performs large iterations or even in infinite loops and other 
cases that need optimization.
Like I said before, it’s still a work-in-progress, and I’m still putting lots 
of factors into consideration, including your incredible insight as the core 
dev team.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/J44HVJLGKYA4I62WJDQTUZCOUQI2IU2H/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: inline Python functions and methods

2021-12-08 Thread TobiasHT
> What inlining usually means is to copy the body of the function
> in place of the call, with appropriate parameter substitutions.
> That would eliminate most of the overhead of a function call, but
> there are problems with doing it in Python. Imported modules would
> have to be located and parsed at compile time, something that doesn't
> currently happen. And it can't be done in general-- the location of an
> imported module isn't know for sure until run time, because changes
> can be made dynamically to sys.path.

This is what I was thinking about as well. That's why I tried to limit the 
operations of this feature to compiletime only, 
If a function fails to be inlined at compiletime due to dynamic behavior of 
python, then the normal function call behavior can be the fallback
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/D7YNBPTLFHH4QBXKDSTPV22WGKPBPSYX/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: inline Python functions and methods

2021-12-08 Thread TobiasHT
So for the point of benchmarks, This is a link to some of the hacks developed 
by Pythonistas to boost some python speed. Among the hacks, there's a topics 
called "reducing dots" and "local variables".
https://wiki.python.org/moin/PythonSpeed/PerformanceTips

Also I would explain to a pythonista that an inline function is that function 
which is copied into the same spot that it's called.
I know it's a somewhat vague definition, but that's what I could think about so 
far.

By scope, yes, I do mean the function's local scope and not surrounding scope. 
And per example you've provided, yes, spam shall appear inside the functions a 
stated, and I think It might not appear in the global scope as hypothesized, 
since it's what we're trying to evade in the first place.

The rest of the concerns you've mentioned above are thinking points that I must 
take into consideration, that's exactly why I was poking around for such 
insights that I might have skipped while thinking about this.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/X4VPPKYMWP57AF6W7NMZFGQDBTHSXIVD/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] inline Python functions and methods

2021-12-07 Thread TobiasHT
The Python community has a 5 year plan to push the limit of speed in Python. 
One of the things that reduces Python execution speed is calling methods or 
functions that are not in the nearest scope.

My suggestion is to introduce inline functions just as they are in C. They can 
be defined as global functions or class methods but are created in the scope of 
the function that is calling it at parsetime. I also don’t think it’ll be hard 
to adapt. inline functions might look something like:

inline def func():
pass

inline async def func():
pass

inline class Executor:
inline def func():
pass

For an inline method, the class must be defined as inline as well, in order to 
bring to scope whatever class variable or method that the inline function might 
rely on.

This is just a suggestion, what do you guys think about it.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/7XSAC2STMEU6WJSLP3DGOGJJGG4IUO3L/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Official means to release the GIL in Python

2021-12-03 Thread TobiasHT
The GIL has been a widely discussed topic in the Python community. It's has 
it's advantages and disadvantages.
I was suggesting that an official way be placed in the Python threading module 
to release the GIL if one needs to perform some tasks that don't need the GIL.

It could be something as simple as

thd = threading.Thread(target = encrypt, nogil = True)

I saw a nogil option in Cython, I just thought it would be great to have it 
fully support in Python as we await the results from Sam Gross's paper.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/5PWD7MXW6EO3ZECUPNXUQHE6HBYZ4JPU/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Enhancing iterator objects with map, filter, reduce methods

2021-12-01 Thread TobiasHT
Matt D wrote:
> In your comprehension example, I'm fairly certain the filtering should be on 
> the post incremented remainder
> [ x+1 for x in [1,2,3] if (x+1) % 2 == 0]

how about
[ sum for num in [1,2,3] if ((sum := num + 1) %2 == 0]
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/QHNJHTU5HRNLVGH7M27G5DZJACYR7GYZ/
Code of Conduct: http://python.org/psf/codeofconduct/