const { width, height, context, lightDirection, depthBuffer, imageBuffer } = this;

            if (context) {
                if (imageBuffer) imageBuffer.data.fill(0);
                else this.imageBuffer = context.createImageData(width, height);
                depthBuffer.fill(Infinity);
            }

            const cameraMatrix = camera.cameraMatrix;
            const cameraPosition = camera.position;
            const backfaceCulling = camera.backfaceCullingEnabled;


            const toScreen = (v) => [
                (v[0] / v[3] + 1) * 0.5 * width,
                (v[1] / v[3] + 1) * 0.5 * height,
                v[2] / v[3]
            ];

            for (const mesh of scene.meshes) {
                const {transformMatrix, geometry} = mesh;
                const {vertices, vertexNormals, indices} = geometry;
                const worldVertices = new Array(vertices.length);
                const worldNormals = new Array(vertexNormals.length);
                for (let i = 0; i < vertices.length; i++) {
                    const v = vertices[i];
                    const n = vertexNormals[i];
                    worldVertices[i] = fast4x1mul(transformMatrix, [v[0], v[1], v[2], 1]);
                    worldNormals[i] = normalize(fast4x1mul(transformMatrix, [n[0], n[1], n[2], 0]));
                }
                const viewVertices = new Array(worldVertices.length);
                for (let i = 0; i < worldVertices.length; i++) {
                    viewVertices[i] = fast4x1mul(cameraMatrix, worldVertices[i]);
                }

                for (const triangle of indices) {
                    if (backfaceCulling) {
                        const [wv0, wv1, wv2] = [
                            worldVertices[triangle[0]],
                            worldVertices[triangle[1]],
                            worldVertices[triangle[2]]
                        ];
                        const faceNormal = computeNormal(wv0, wv1, wv2);
                        const camToTri = [
                            wv0[0] - cameraPosition[0],
                            wv0[1] - cameraPosition[1],
                            wv0[2] - cameraPosition[2]
                        ];

                        if (dotProduct(faceNormal, camToTri) <= 0) {
                            continue;
                        }
                    }

                    const [vv0, vv1, vv2] = [
                        viewVertices[triangle[0]],
                        viewVertices[triangle[1]],
                        viewVertices[triangle[2]]
                    ];

                    const [n0, n1, n2] = [
                        worldNormals[triangle[0]],
                        worldNormals[triangle[1]],
                        worldNormals[triangle[2]]
                    ];


                    let triangles = [[vv0, vv1, vv2]];
                    let normalSets = [[n0, n1, n2]];

                    for (const [axis, min, max] of [[0, -1, 1], [1, -1, 1], [2, 0, 1]]) {
                        const newTriangles = [];
                        const newNormals = [];
                        for (let i = 0; i < triangles.length; i++) {
                            const clipped = clipTriangle(triangles[i], normalSets[i], axis, min, max);
                            for (const [clippedVertices, clippedNormals] of clipped) {
                                newTriangles.push(clippedVertices);
                                newNormals.push(clippedNormals);
                            }
                        }
                        triangles = newTriangles;
                        normalSets = newNormals;
                        if (triangles.length === 0) break;
                    }

                    for (let i = 0; i < triangles.length; i++) {
                        const [cV0, cV1, cV2] = triangles[i];
                        const [nV0, nV1, nV2] = normalSets[i];

                        const [vv0, vv1, vv2] = [toScreen(cV0), toScreen(cV1), toScreen(cV2)];

                        const colorV0 = Math.max(0, dotProduct(nV0, lightDirection)) * 255;
                        const colorV1 = Math.max(0, dotProduct(nV1, lightDirection)) * 255;
                        const colorV2 = Math.max(0, dotProduct(nV2, lightDirection)) * 255;

                        this.fillTriangle(vv0, vv1, vv2, colorV0, colorV1, colorV2);
                    }
                }
            }

            context.putImageData(this.imageBuffer, 0, 0);
        }



Optimize this code to run faster. Remove any redundancies if present. Make sure it still works and functions the same.