Skip to content

Native performance is terrible with Python #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jasonzhengbj opened this issue Aug 7, 2023 · 3 comments
Closed

Native performance is terrible with Python #350

jasonzhengbj opened this issue Aug 7, 2023 · 3 comments
Assignees

Comments

@jasonzhengbj
Copy link

jasonzhengbj commented Aug 7, 2023

I used docker image ghcr.io/graalvm/graalvm-community (tag: 20.0.2-ol7-20230725) and install GraalPy 3.10.8 (GraalVM CE Native 23.0.1).
I use simple code to test native performance. standalone application performance is slower.

Pythn code:

import datetime

if __name__ == '__main__':
    print(datetime.datetime.now())
    s = 0
    loop = 500
    for i in range(loop):
         for j in range(loop):
             for k in range(loop):
                s += 1
    print(f'loop: {s}')
    print(datetime.datetime.now())
    

graalpy spend time about 1.5s.

sh-4.2# graalpy loop.py
2023-08-07 09:01:32.211000
loop: 125000000
2023-08-07 09:01:33.708000

native spend time about 6.5s.

sh-4.2# graalpy -m standalone binary   --module loop.py  --output loop 
sh-4.2# ./loop
2023-08-07 09:39:43.672000
loop: 125000000
2023-08-07 09:39:50.213000
@jasonzhengbj jasonzhengbj changed the title > Hi. It's a new feature in version 23.0, you need to update to get it. It's a graalpy-specific module that we ship as a part of our standard library. Native performance with Python Aug 7, 2023
@jasonzhengbj jasonzhengbj changed the title Native performance with Python Native performance is terrible with Python Aug 8, 2023
@syan-cn
Copy link

syan-cn commented Aug 8, 2023

After updating to the dev version 23.1.0, I found that the binary file was always faster than the .py file for your simple code. It took about 1s to run for the binary file, while the .py file cost about 2s.

.py file:

2023-08-08 23:11:35.133000
loop: 125000000
2023-08-08 23:11:37.153000

binary file

2023-08-09 14:12:05.070000
loop: 125000000
2023-08-09 14:12:06.101000

And I found the time of generation was also faster. The total time spent on obtaining the binary file was about half of that before.

@syan-cn
Copy link

syan-cn commented Aug 8, 2023

When I tested the native performance of pandas, graalpy made an executable file successfully. But there was an error when I run the file:

Traceback (most recent call last):
  File "/Library/Java/JavaVirtualMachines/graalvm-community-openjdk-21+30.1/Contents/Home/languages/python/lib/python3.10/runpy.py", line 196, in _run_module_as_main
  File "/Library/Java/JavaVirtualMachines/graalvm-community-openjdk-21+30.1/Contents/Home/languages/python/lib/python3.10/runpy.py", line 86, in _run_code
  File "/private/var/folders/41/fffb7hhx5pj6ztn83jcb__n00000gn/T/tmp16n888e5/__main__.py", line 5, in <module>
  File "/Users/shanshu/SourceCode/graal/venv/lib/python3.10/site-packages/pandas/__init__.py", line 11, in <module>
  File "/Users/shanshu/SourceCode/graal/venv/lib/python3.10/site-packages/numpy/__init__.py", line 140, in <module>
  File "/Users/shanshu/SourceCode/graal/venv/lib/python3.10/site-packages/numpy/core/__init__.py", line 23, in <module>
  File "/Users/shanshu/SourceCode/graal/venv/lib/python3.10/site-packages/numpy/core/multiarray.py", line 10, in <module>
  File "/Users/shanshu/SourceCode/graal/venv/lib/python3.10/site-packages/numpy/core/overrides.py", line 6, in <module>
SystemError: Cannot load "libsulong-native.dylib". Internal library path not set

The test file:

import time

s = time.time()

import pandas as pd

for i in range(100):
    pd.DataFrame()

e = time.time()
print("total time:", e-s)

And I used the command with the option of virtual environment

python -m standalone native --module <py_file> --output <output_file> --venv ./venv

@timfel
Copy link
Member

timfel commented Sep 11, 2023

@syan-cn with the upcoming release using native extensions in the binaries works. I tried pandas, numpy, and pytorch.

@timfel timfel closed this as completed Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants