Jump to content

wrangle performance when creating new points


Recommended Posts

I'm using about 1000 points in a point wrangle SOP as seeds to generate lines, totalling about 20,000,000 points... performance seems almost single threaded, which I assume is due to the creation of new geo.  Is there any way I can speed it up?  Here's the code in question if anything obviously jumps out:

 

// trace lines through nested velocity volumes
void stepRK4(vector pos; const int prim; const float dt; const vector V0; float dir)
{
    vector V1 = volumesamplev(1, prim, pos + (0.5 * dt) * V0) * dir;
    vector V2 = volumesamplev(1, prim, pos + (0.5 * dt) * V1) * dir;
    vector V3 = volumesamplev(1, prim, pos + dt * V2) * dir;
    pos += (dt / 6) * (V0 + 2 * (V1 + V2) + V3);
}

void step_forward(vector pos; float dir)
{
    float dist = length(pos);
    
  	// There are volumes at 5 levels of detail, starting from the origin.  This distance metric chooses which to sample from
    int prim = int(max(log(dist / 8. * 2) / log(4) + 1, 0));
    // advection step based on the voxel size
    float vd = volumevoxeldiameter(1, prim);
    float dt = vd * 2;
    vector vel = volumesamplev(1, prim, pos) * dir;
    stepRK4(pos, prim, dt, vel, dir);
}
int steps = 10000;

int pr1 = addprim(geoself(), "polyline", @ptnum);
int pr2 = addprim(geoself(), "polyline", @ptnum);
vector pos1 = @P;
vector pos2 = @P;

for (int i=0; i<steps; i++)
{
    step_forward(pos1, 1);
    if (length(pos1) >= 1 && length(pos1) < 1000)
    {
        int newpt1 = addpoint(0, pos1);
        addvertex(geoself(), pr1, newpt1);
    }
    step_forward(pos2, -1);
    if (length(pos2) >= 1  && length(pos2) < 1000)
    {
        int newpt2 = addpoint(0, pos2);
        addvertex(geoself(), pr2, newpt2);
    }
}

 

Link to comment
Share on other sites

Can't reproduce your exact situation without the rest of the setup, but the Point Generate SOP, which I suppose is implemented reasonable well in C++ should be a good enough comparison in terms of a high limit. 2e+07 points is basically instantaneous on my machine, 0.006 secs on the monitor to be exact. Even Point Jitter SOP all those points is just 0.1 secs.

Are you sure you're not being betrayed by the viewport? Usually the viewport is by far the biggest slowdown when it comes to changing geometry.

Also, VEX is very decent in terms of speed, but you might want to try the HDK itself. You can easily without all the compiling hassle with inlinecpp

Link to comment
Share on other sites

you may benefit from compiled foreach loop for this

since as I understand it all point/vertex/prim creation within a single wrangle has to be queued at the end on a single thread as each of your points may want to add vertices to any primitive for example so wrangle can't assume that the operation are safe to run in parallel for example even though you know that they are in your case

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...