Skip to content

General Performance Improvements #269

@JBloss1517

Description

@JBloss1517

The goal of this issue is to improve the over all performance of pynite. This would close #251 and #189. When I was profiling the usage of largish models, it was clear there were a handful of bottlenecks that slowed the whole thing down. As an example, if you see @angelmusonda profile in #251, you will see PhysMember.descritize takes up 16.6s of the total 25.9 secs.

My plan would include:

  • Introduce a KD tree as a second node storage used for faster near node queries.
  • Use the KD tree to improve the performance of FEModel3D.merge_duplicate_nodes method
  • Use the KD tree to improve the performance of PhysMember.discretize method
  • Use a csr_matrix when partitioning matrices in the Analysis._partition method
  • Add some unit tests around merge_duplicate_nodes to prevent regression from new approach
  • Add some unit tests around discretize method to prevent regression
  • Add internal caching of expensive computed fields in Quad3D and Member3D to avoid recomputing the same value multiple times

My current plan with the KD tree is to build it when you call FEModel3D.analyze and keep using it until you add a new node. For most models with only one call to analyze, this should keep the time to build it to a minimum. I would use the scipy.spatial.KDTree since scipy is already a project dependency. The KD Tree would only be used for near node queries (at least for now) and leave the other operations on the nodes using the internal nodes dictionary.

I would love some feedback though from other pynite users, if there are other things that are relatively simple that the KD tree would help out with. Or please speak up if you think the KD approach is not a good idea.

And for those not familiar with the KD tree, this Wikipedia link to k-d tree might be helpful to understand how they can help us improve the finding of near nodes.

Current work is being done here: https://github.com/Apex-Engineers-Inc/Pynite/tree/issue-269-general-performance-improvements


2025.06.26 - Update: Currently on my machine the full test suite started off taking 166s, but after making these changes I have checked off so far, the test suite now takes 93s (~1.78x speed up so far). But testing my own test project with only framing members, it went from 15.8s to 4.5s (~3.5x speed up).
Upwards of 90% of the test suite time is the test_tank.py which contains numerous quad elements. I am currently looking into getting this down further as I can see a small handful of methods are taking the bulk of time.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions