I am generating large numbers (several thousand, say) of long random fractal path3s on a sphere (up to a few thousand points each), using an external program. I want to produce a 3D figure in Asymptote displaying these paths. Currently, my workflow is to use my external program to write all the data into a large Asymptote script and compile it.

This scheme works when I try very small examples (i.e. with dozens instead of thousands of paths), but it very quickly becomes prohibitively slow and memory intensive. I could write the data to a text file and read it into Asymptote instead, but this would be kind of ugly, and it seems unlikely that the bottleneck is parsing the .asy file. Also, this problem seems to be specific to 3D, so I'm hoping that there's some appropriate combination of 3D options---or something like that---that solves the problem.

It's hard to give a closely representative MWE given the external data generation, but this program (which displays a 10,000-step long random walk) captures the essential issue.

import three;

triple q = (0.0,0.0,0.0);
path3 p = q;

for(int i=1;i<=10^4;++i){
  q = q + (2*unitrand()-1, 2*unitrand()-1, 2*unitrand()-1);
  p = p -- q;


TL;DR What's the best way to efficiently render many path3s?

1 Answer 1


You can greatly speed up your example by changing path3 to guide3 and drawing with a thin pen:


See http://asymptote.sourceforge.net/doc/Paths-and-guides.html#index-guide

  • I tested 300, 600 and 900 iterations. With path3, I got 1.24s, 4.65s and 11.69s. With guide3, I got 0.55s, 1.04s and 1.41s. Feb 22, 2017 at 6:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .