Fastest way to move vertices with python I'm still a python beginner and I'm writing a script/addon that moves vertices of a mesh following a "long" calcul every time frame changes. Something like :

import bpy

def MoveVertices(scene):
    obj = bpy.data.objects['Cube4']
    '''creating a copied mesh (.to_mesh) here to retrieve vertices positions later
    '+ setting some variables
    '''
    for v in obj.data.vertices:
        '''long calcul to find the vector
        ' like 20 lines of code some if statements and calculus
        '''
        v.co += vector
    ''' setting some variables + removing tmp mesh (.remove)'''
    return {'FINISHED'}

def register():
    bpy.app.handlers.frame_change_post.clear()
    bpy.app.handlers.frame_change_post.append(MoveVertices)

def unregister():
    bpy.app.handlers.frame_change_post.remove(MoveVertices)

if __name__ == "__main__":
    register()


What happens of course is when there is a lot of vertices the system starts to slow down a lot. I know for performance sake I should write in C/C++ and do a custom blender build but I was wondering if there isn't a more efficient way to move bunch of vertices in "real time" with python.

Here are my questions :


does a straight loop through all vertices like I'm doing is the best
way to go concerning calcul speed?
would using bmesh help in that matter?
what about slicing the amount of vertices and launching the calcul
in parallel for each chunks (with a modal timer operator) ? Would that be an idea ?
is there something I'm missing in the python api that could help ?


Thx a lot for your help.
foreach_set() is actually very fast but not usable in my case because I'm not always going through all vertices in all cases.
It seems that the "for" loop is the best way to go.

Using bmesh actually is a little faster because it doen't refresh the scene each time the script changes the location of a vertex.

Thx @CoDEmanX and  @MikePan for the help.