1. A method for transforming asynchronous code into more efficient, logically equivalent asynchronous code, comprising: converting program code into a first syntax tree; generating a dependency graph from the first syntax tree with each node of the dependency graph corresponding to a code statement and having an assigned weight; performing weighted topological sorting of the dependency graph to generate a sorted dependency graph; and generating a second syntax tree from the sorted dependency graph.