Fastest way to check mesh data (is it changed or not)?

In my addon I draw some thing and as a optimization, to not recalculate what to draw each frame I have 2 checks:

  1. I save object.matrix_world and then compare saved matrix with current > if they are different I go to recalculate without checking mesh.
  2. If matrices are same I go check mesh. I use API instrument data.vertices.foreach_get() (thanks to kkar for advise) as fast way to store vertices coordinates data inside numpy array. I compare then saved array with current newly created and if they same I do not recalculate what to draw.

Numpy work really fast, comparing those two arrays go really fast. But this optimization is still slow (at least it not fits my expectations) because each time I again ang again do this vertices.foreach_get() and write coordinates to new empty numpy array to compare it… and this step is not fast enough. In edit mode it even slower because bmesh has no vertices.foreach_get() so I have to do object.update_from_editmode() and only then do vertices.foreach_get() (writing coordinates by extracting in for v in data.vertices loop work even slower).

I noticed how Blender work with high poly meshes when entering edit mode. First going some lag and then it go absolutely smooth and fast, untill any mesh editing begin. I think some check has to exist to know if it need to just stay idle or start recalculate mesh.

So here is the question - do anyone have any ideas of better (faster) ways to check is mesh same as in previous frame or different? (by using Python API of course)

I feel like I made some not bad but pretty dumb solution… it work pretty well for low/mid poly models, it sucks hard on high poly.

It has to exist something better and faster. Maybe exist some way to store mesh data in variable and then compare it with new data as just two pieces of bytes in memory, without necessity to dig through each vertex coordinates and compare thousandths of floats to find difference.

you draw something? not sure I understand but there is what crossed my mind reading.
using a low render resolution with open CV to analyze in 2D if changes. then see what frame you can render in a higher resolution?

No no, not about render. I work on addon for setting origin and want to ad some visualizations.

Like this

I draw spots and cage for model > to know what to draw I ned to calculate it > to calculate It I need to go through all vertices > to make things fast I need optimozation that let me know when I can reuse already calculated coordinates if mesh same as before (unchanged).

I already added manual refresh button, but it is not cool… I want it to work in auto refresh mode with good enough performance (for high poly meshes).

I looking for better way (better than what I made) to know if mesh is unchanged (or changed).

couldn’t you use bounding box? object.bound_box

Nope. Long story. Shortly 1. it only local (I also calculate global orientation version, for future want more orientations) 2. I calculate more things than just bound.

the closest you’re going to get with the current API is a depsgraph update, unfortunately depsgraph updates fire on any change to the dependency graph, there’s no way to filter it by type, so if you change selections, etc- it will trigger an update.