The slowness is primarily down to the default for mapping to use the SVG element rather than the Canvas element. The former involves creating thousands of new DOM nodes, the latter draws the pixels directly (hence the term Canvas). Canvas can handle drawing over 100,000 nodes in less than a second in the browser. Pretty sure GPX Editor uses Leaflet. Leaflet supports using Canvas for drawing paths / tracks if the option is set to true. By default it is set to false for maximum browser compatibility.

In terms of an algorithm you can do a horizontal and vertical walk of your simple graph taking your input as example

0,1 0,2

1,0 1,1

1,1 1,2

2,0 2,1

2,1 2,2

1,0 2,0

0,1 1,1

1,1 2,1

0,2 1,2

1,2 2,2

First first we take all the lines that move vertically and sort the start point of the line by its x, and then its y coordinate so we end up with

0,1 0,2

1,0 1,1

1,1 1,2

2,0 2,1

2,1 2,2

You then walk through the sorted set of vertical lines looking for a join in the next line. Whenever a gap appears you output a line and start building the next one.

So 0,1 - 0,2 is a single line not joining to any of the other lines so one line output is 0,1 - 0,2

1,0 - 1,1 joins to 1,1 - 1,2 so the next vertical line output 1,0 - 1,2

2,0 - 2,1 join to 2,1 - 2,2 and you reach the end of the list so you output your final vertical line 2,0 - 2,2

So the three vertical lines output are 0,1 - 0,2 ; 1,0 - 1,2; 2,0 - 2,2

You then take all the lines which move horizontal and sort by y then x

1,0 2,0

0,1 1,1

1,1 2,1

0,2 1,2

1,2 2,2

1,0 to 2,0 does not join to the next line so you output first horizinal line 1,0 - 2,0

0,1 - 1,1 joins 1,1 - 2,1 so you output your next line 0,1 - 2,1

0,2 - 1,2 joins 1,2 - 2,2 so you output your third horizintal line 0,2 - 2,2

So you output 6 lines to draw your L shaped box

It is not the minimum number of lines, you could have a single line / path for an L shape but it is trivial to implement and gets you down to low enough number of lines very quickly.

For a 30 x 1 grid you end up with 33 lines

for a 30 x 2 grid you end up with 34 lines

for 30 x 3 grid you end up witth 35 lines

fora 30 x 30 grid you end up with 62 lines / tracks

You will have more lines for incomplete grids but not massive numbers a browser cannot cope with even in SVG mode. For SVG you should keep the number of tracks below about 1000. For Canvas you can scale into tens of thousands easily.

Remember you are not trying to solve the TSP problem (which is non trivial beyond a certain number of nodes) you are just trying to get it "good enough" for your purposes.

P.S If you truly want to minimise the tracks as much as possible you will want to use a Taxicab geometry matrix to solve.