I think it’s expected that a JS-coded line drawing function will be slower than the C++ version. Out of curiosity, why do you want to draw lines? Are you going for wireframe graphics? For polygon-based 3D graphics, you’ll definitely need a specialized pixel fill function instead.
Note that the renderer I wrote predated the native triangle fill function. If I were to implement something now, I’d probably go with using that instead of implementing my own, though it does come at the cost of losing dithering. With my JS approach, there really wasn’t a performance cost for dithering since it just switched out which of the specialized fill functions it used. It just needed versions for ABABAB and BABABA pixel patterns in addition to single color, since the 1/4 and 3/4 patterns just alternate between the 50% pattern and single color on alternating columns.
In case you haven’t seen it, Space Rocks 3D also included some ad-hoc profiling code which I used to check where the code is spending most of its time. One major gotcha for the hardware targets is that you need to be extremely careful to stick to integer (or fixed point) math for all inner loops. Having a floating point value creep in, for example due to exceeding the expected value range, will wreck performance. The profiling helped catch some of those, and also kept me on track for optimizing the parts that mattered.
In case you haven’t seen it, check out the Carrier 3D (unfinished work in progress) thread. That’s the most recent version of the renderer, and the thread also has some implementation notes and additional resource links.
Good luck on your project!