rather than it being a code optimization board, that's generally the sort of thing that the "programs" section is for, meaning that you have a question about a particular program you're working on, rather than something having to do with a specific function.
the fastest way to implement this would be to
1) use P3D, it'll be faster, and P2D and JAVA2D don't support gradients in alpha or color
2) draw a quad shape for the line, so that it can change its thickness along the way
something like this:
(not tested but adapted from the old BGraphics, should be close if not working)
Code:
void thickFlatLine(float ox1, float oy1,
float r1, float g1, float b1, float a1,
float ox2, float oy2,
float r2, float g2, float b2, float a2,
float thickness) {
float dX = ox2-ox1 + EPSILON;
float dY = oy2-oy1 + EPSILON;
float len = sqrt(dX*dX + dY*dY);
float rh = thickness / len;
float dx0 = rh * dY;
float dy0 = rh * dX;
float dx1 = rh * dY;
float dy1 = rh * dX;
beginShape(QUADS);
fill(r1, g1, b1, a1);
vertex(ox1+dx0, oy1-dy0);
vertex(ox1-dx0, oy1+dy0);
fill(r2, g2, b2, a2);
vertex(ox2-dx1, oy2+dy1);
vertex(ox2+dx1, oy2-dy1);
endShape();
}