The speed optimization problem over a path aims to find a set of speeds over each arc of the given path to minimize the total cost, while respecting the time-window constraint at each node and speed limits over each arc. In maritime transportation, the cost represents fuel cost or emissions, so study of this problem has significant economic and environmental impacts. To accommodate different fuel and emission models, we allow the dependence of the cost on the speed to be a general continuously differentiable and strictly convex function, and different across the arcs. We develop an efficient algorithm that is able to solve instances of 1,000 nodes in less than a second. The algorithm is 20 to 100 times faster than a general convex optimization solver on test instances and requires much less memory. The solutions found at intermediate steps of our algorithm also provide some insights to ship planners on how to balance the operating cost and service quality.