-
Notifications
You must be signed in to change notification settings - Fork 15
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
Geometry manipulation slow compared to native manipulation #1215
Comments
Hi @andreas-hilti - delay is expected indeed, since the native implementation is making direct usage of the library, whereas PyAnsys Geometry includes the library overhead, safety rails and gRPC communication with the service. Nonetheless these values are pretty high... let me investigate in depth. This might take some time. |
Investigating... |
Findings:
# TIME IT
############################################
start_time = time.time()
w = 0.05
body1 = create_box_body(design, "box1", w, w, w)
body2 = body1.copy(design, "box2")
body2.translate(UNITVECTOR3D_X, w / 2)
for i in range(1000):
newBody1 = body1.copy(design, f"box1_{i}")
newBody2 = body2.copy(design, f"box2_{i}")
newBody1.translate(UNITVECTOR3D_X, w * 1.1 * i)
newBody2.translate(UNITVECTOR3D_X, w * 1.1 * i)
newBody1.intersect(newBody2)
end_time = time.time()
############################################
With all these changes, time goes down to |
Performed a cProfiling operation on the code... There is little to nothing else that can be done on the Python side of things. Have a look at the file. Operations needed on your side are:
Find attached the file. I have only profiled the part we are interested in: import time
import cProfile, pstats
...
# TIME IT
############################################
start_time = time.time()
profiler.enable()
w = 0.05
body1 = create_box_body(design, "box1", w, w, w)
body2 = body1.copy(design, "box2")
body2.translate(UNITVECTOR3D_X, w / 2)
for i in range(1000):
newBody1 = body1.copy(design, f"box1_{i}")
newBody2 = body2.copy(design, f"box2_{i}")
newBody1.translate(UNITVECTOR3D_X, w * 1.1 * i)
newBody2.translate(UNITVECTOR3D_X, w * 1.1 * i)
newBody1.intersect(newBody2)
profiler.disable()
end_time = time.time()
############################################
# Export profiler output to file
stats = pstats.Stats(profiler)
stats.dump_stats("profiledata.prof") If you sort out the times by "tottime" you will see that around 27secs are spent in a "blocking" condition coming from the gRPC channel. Meaning that this is the time spent in the service... Client side has its "problems" for sure like type checking, keeping track of server side status etc. but those are minimal in comparison. |
This is the file used on my side... |
🔍 Before submitting the issue
🐞 Description of the bug
When doing geometry operations via pyansys-geometry, this is at least an order of magnitude slower than using SpaceClaim/Discovery scripting (and probably even more when compared to the SpaceClaim API).
Attached is just a dummy example to illustrate the point.
📝 Steps to reproduce
Run the attached scripts with the geometry service and inside SC (with the same geom kernel).
I observed (but timings are noisy):
Geometry Service:
Elapsed time: 38.75350642204285
SC:
Elapsed time: 3.78514099121
geom_service_performance.zip
💻 Which operating system are you using?
Windows
📀 Which ANSYS version are you using?
2024 R2
🐍 Which Python version are you using?
3.10
📦 Installed packages
The text was updated successfully, but these errors were encountered: