modeled in various ways and export STLs and compare the log values as a representation of the complexity of the internal mesh.

The most basic example:

cube(size = [4,9,1], center = false);

which the log reports as:

Rendering Polygon Mesh using CGAL...
Geometries in cache: 2
Geometry cache size in bytes: 1456
CGAL Polyhedrons in cache: 0
CGAL cache size in bytes: 0
Total rendering time: 0:00:00.020
Top level object is a 3D object:
Facets: 6

Interestingly if one exports an STL, both files create a 1,535 byte STL file — presumably there is some optimization which happens when creating the STL.

OpenSCAD does basically no work in the first example because you tell it exactly what you want, a cube. All it has to do is this, which is a constant-time operation which requires nothing in memory other than a cube.

In the second example you’re asking it to do a ton of work. It’s no longer just building a sphere but instead it has to create a bunch of cylinders, find the 3D convex hull for pairs of them, union them and then difference them. There’s no longer just the 8 vertices of a cube to keep in memory (those numbers with 100x multipliers are the cache, so I assume concerned with memory used during calculation rather than anything to do with the output) but all the cylinders and convex hulls you use along the way.

I think OpenSCAD can only be as efficient as you ask it to be.

There’s a very easy improvement you could make: instead of using hull in your endmillcut module, union the two cylinders with a rectangular prism. The result should have exactly the same geometry but without all the complex maths in the background.

Rather than use cylinders, you could also use hexagonal prisms or some other approximation. Cylinders are much more complex shapes (lots more edges and vertices) so harder to deal with.

Yes, but it adds an additional complexity, and won’t work with a ball-nosed endmill — I did do something similar when implementing a cove radius endmill, so will keep it in mind.

Linear extrude the length of the toolpath (center to center)

Rotate extrude again and rotate

This should still be a lot more efficient than the convex hull operation.

And I don’t think I’d agree that this is more complex than a hull operation. When you know what a hull operation is it might seem simpler but I think a lot of people wouldn’t be familiar with them, while union is pretty straightforward.