What is new, and what is not
psync stands on a lot of earlier work. This chapter says, idea by idea, who did it first, what psync does differently, and where its speedups come from. Every chapter that introduces one of these ideas ends with a short Prior work and novelty section that goes into more detail.
Each source below was read from the paper or the official documentation (the research notes, with
a quote and section for each, are in the repository at research/prior-work-verified.md). Where a
source could not be read, this chapter says so rather than guess.
The short version
Almost every single idea in psync has been done before, often decades ago:
- Overlapping independent awaits automatically. ReSynchronizer did it for JavaScript in 2021, with a side-effect analysis and a table of file-system and network calls.
- Joining independent chains at compile time. GHC’s ApplicativeDo does it for Haskell.
- Raising failures in their sequential order. Haxl and Safe Futures both do it.
- Prefetching I/O in loops. Compilers have done it since 1996.
- Proving that a concurrent schedule equals the serial one. Safe Futures proves it.
- Cross-crate summaries over MIR. These exist for memory-safety analysis.
- Predicting a speedup from a dependency graph. WebProphet does it for web pages.
Measured on the same 16 real-world functions, scheduling them by ReSynchronizer’s rules gives a geometric mean of 1.28×, and psync 3.79× (details below).
What psync adds is the combination, and a few specific differences in each idea that the earlier systems do not have:
- Effects compared by target, not by kind. ReSynchronizer keeps every file read behind every file write. psync compares paths, URLs and keys, so two writes to different files overlap. When the targets are only known at run time, a gate compares the values, file identity included, and falls back to the original order when they collide. The closest precursor, Quasi-Static Scheduling for Safe Futures, places barriers by static alias analysis, for memory only.
- Rust’s control flow.
?,return,breakandcontinueinside chains, and loops turned into bounded prefetch. ReSynchronizer never moves code across areturnor a loop test; ApplicativeDo never reorders effects at all. - No new runtime, no threads, no annotations. The rewrite is one future that polls its chains on the caller’s task. It works on Tokio, embassy or a microcontroller, with borrowed data. Haxl needs its own monad, Safe Futures a modified JVM, Æminium a new language, DPJ annotations.
- A certificate per function, checked by a proven-sound checker, against a model of the outside world. Translation validation (Pnueli, Necula) checks a compiler’s output once per run; Safe Futures proves schedules equivalent for memory. psync’s Lean checker validates each rewritten function’s schedule, with I/O events allowed to reorder only where a commutativity specification of the service says they commute.
Idea by idea
| Idea | Closest prior work | What it already did | What psync does differently | More |
|---|---|---|---|---|
| Overlap independent awaits | ReSynchronizer (ECOOP 2021), AutoFutures (2012) | automatic await overlap in JavaScript, with a file/network effect table; futures for independent Java calls | Rust, at compile time, in a macro; effects by target; exits and loops; gates and certificates | Basic concepts |
| Chains joined in levels | ApplicativeDo (Haskell 2016), Haxl (ICFP 2014) | independent segments joined concurrently, decided from bindings | reorders past statements whose effects are independent, not only their bindings | Basic concepts |
| Early exits | Haxl §8.1, Safe Futures (OOPSLA 2005) | the leftmost exception wins, so the result is deterministic | Rust ?, return, break, continue, across chains on one task | Early exits |
| Loops | Mowry et al. (OSDI 1996), futures::StreamExt::buffered | compiler-inserted I/O prefetch hints; hand-written bounded concurrency | runs the real calls early, so it checks items for conflicts | Loops |
| Effects of the outside world | ReSynchronizer Table 1, DPJ (OOPSLA 2009), QSS (PPoPP 2008) | effect tables per environment; nested regions; barriers from alias analysis | targets that overlap by prefix, value gates with file identity | Side effects |
| Summaries across crates | Zhou, Sun and Criswell (2023), MirChecker (CCS 2021) | per-function MIR summaries for whole programs | the summaries hold effects and their targets, fed back to the macro | From MIR to summaries |
| Certificates | Translation validation (1998, 2000), CompCert, Safe Futures | per-run validation; a verified compiler with identical I/O traces; serial equivalence for memory | I/O may reorder under a commutativity spec; a Lean checker proved sound | Certified schedules |
| World model | Scalable Commutativity Rule (SOSP 2013), linearizability (1990) | interface-level commutativity of POSIX calls; atomic operations | the same idea, used to justify reordering a client’s calls | The outside world |
| Predicting the speedup | Coz (SOSP 2015), Yang and Miller (1988), WebProphet (NSDI 2010) | virtual speedups; critical paths; what-if latency from a fetch graph | the graph comes from the code, per control path, for one automatic rewrite | Predicting the speedup |
| Synchronous code (Phase II) | thread-level speculation (ISCA 2000), SpecHint (OSDI 1999), Rayon | speculative threads that stall on system calls; speculative read hints; data parallelism by hand | real calls, reads and ordered writes, on worker threads, chosen automatically | Phase II design |
Where the speedup comes from
psync does no work faster. It waits less. When a function makes several calls that wait on the network or the disk, the sequential code waits for each in turn: the sum of the waits. After the rewrite, each level waits as long as its slowest chain. So the speedup is roughly
speedup ≈ (sum of all waits) / (sum over levels of the longest chain in each level)
and psync can compute that number before it rewrites anything (Predicting the speedup). This is why the speedups below are 1.6× to 6.9×. Three waits of equal length give 3×; a loop of six items with a bound of 16 gives 6×; a function whose second half must wait for its first gains little.
Measured: the same functions under ReSynchronizer’s rules
The closest earlier tool, ReSynchronizer, works on JavaScript, so it cannot run on these Rust
functions. Instead, psync can schedule a function by ReSynchronizer’s rules, with
#[psync::graph(baseline = resync)]:
- an await may start earlier and be awaited later, but only within one block: nothing moves across a loop or a branch (its §4.6);
- effects are one per environment (its §4.4): every file effect touches “the file system”, every network or service call “the network”, so a write orders every other access to its environment;
- no run-time checks, and none of psync’s hints (
speculate,independent).
cargo run --example graph_suite --no-default-features -- --brief --resync times each of the 16
functions three ways: as written, by these rules, and by psync. Two runs agreed to 0.02×.
graph_suite --resync; the baseline is ReSynchronizer's rules applied to Rust by psync, not the JavaScript tool.| Functions | ReSynchronizer’s rules | psync | |
|---|---|---|---|
| all | 16 | 1.28× | 3.79× |
without a scheduling hint (speculate, independent) | 11 | 1.44× | 3.89× |
| loops (P2, P3) | 9 | 1.00× | 4.99× |
| straight-line code (P1, P4) | 7 | 1.77× | 2.67× |
Read the figure row by row and the differences have three causes:
- Loops: 1.00× against 3.1× to 6.9×. All nine loops stay sequential under the rules, because nothing moves across a loop test. psync prefetches the items, with a check per item.
- Moving past a loop or a branch. zed reads the database after a loop over S3 manifests, and the read needs nothing from the loop. psync starts it before the loop: 2.50×. By the rules it must wait: 1.00×.
- Targets, and hints. matrix-rust-sdk makes eight PUTs to distinct account-data event types;
greptimedb uploads a Parquet file that does not need the index it builds first. By the rules
every write is “the network”, so each waits for the one before: 1.00×. psync compares the
targets, and with the function’s
speculatehint (the PUTs and the upload are idempotent, so they may run before an earlier call has succeeded) reaches 4.49× and 1.57×.
Where the rules apply, they match psync exactly: agave, loco, lemmy’s six reads and lighthouse run at the same speed both ways (3.41×, 1.57×, 5.98×, 1.67×). For straight-line awaits without writes, ReSynchronizer already had the idea, and psync adds nothing to the speed.
Two cautions. The baseline is psync’s reading of ReSynchronizer’s published rules, applied to Rust; it is not the JavaScript tool, whose analysis of particular libraries may differ. And these 16 shapes come from psync’s own audit, which looked for what psync rewrites; a sample chosen by ReSynchronizer’s authors might show a smaller gap.
What psync does not claim
- It is not sound on its own. It assumes that names mean what they say (
getreads,putwrites), that unknown calls only read, and that different receivers are different resources (What is checked, what is assumed). A certificate proves a schedule safe given the effects psync found, not that it found the right ones; the proof that summaries over-approximate real accesses covers a fragment of MIR (Certified schedules). - It does not batch or cache. Haxl, Stitch and DataLoader merge many small reads into one request. psync sends the same requests, at the same time.
- It can hurt under load. Offering every request at once can overload a server: 32 clients refreshing DataFusion’s catalog together ran at 0.76× (kube-rs and DataFusion).
Sources
- Arteca, Tip, Schäfer. Enabling Additional Parallelism in Asynchronous JavaScript Applications (ReSynchronizer). ECOOP 2021.
- Marlow, Brandy, Coens, Purdy. There is No Fork (Haxl). ICFP 2014.
- Marlow, Peyton Jones, Kmett, Mokhov. Desugaring Haskell’s do-notation into Applicative Operations (ApplicativeDo). Haskell Symposium 2016.
- Molitorisz, Schimmel, Otto. Automatic Parallelization using AutoFutures. KIT, 2012 (extended abstract).
- Stork et al. Æminium: A Permission-Based Concurrent-by-Default Programming Language Approach. TOPLAS 2014.
- Bocchino et al. A Type and Effect System for Deterministic Parallel Java. OOPSLA 2009.
- Welc, Jagannathan, Hosking. Safe Futures for Java. OOPSLA 2005.
- Navabi, Zhang, Jagannathan. Quasi-Static Scheduling for Safe Futures. PPoPP 2008.
- Rinard, Diniz. Commutativity Analysis. TOPLAS 1997.
- Clements et al. The Scalable Commutativity Rule. SOSP 2013.
- Herlihy, Wing. Linearizability. TOPLAS 1990.
- Li et al. MirChecker. CCS 2021. Zhou, Sun, Criswell. Fast Summary-based Whole-program Analysis to Identify Unsafe Memory Accesses in Rust. arXiv 2310.10298, 2023.
- Ho et al. Charon. arXiv 2410.18042. Ho, Protzenko. Aeneas. ICFP 2022.
- Pnueli, Siegel, Singerman. Translation Validation. TACAS 1998. Necula. Translation Validation for an Optimizing Compiler. PLDI 2000.
- Leroy. Formal Verification of a Realistic Compiler. CACM 2009. Bell. A Proof Theory for Loop-Parallelizing Transformations. Princeton, 2014.
- Mowry, Demke, Krieger. Automatic Compiler-Inserted I/O Prefetching for Out-of-Core Applications. OSDI 1996.
- Curtsinger, Berger. Coz. SOSP 2015. Yang, Miller. Critical Path Analysis for the Execution of Parallel and Distributed Programs. ICDCS 1988. Zhou et al. wPerf. OSDI 2018. Li et al. WebProphet. NSDI 2010.
- Steffan et al. A Scalable Approach to Thread-Level Speculation. ISCA 2000. Chang, Gibson. Automatic I/O Hint Generation through Speculative Execution (SpecHint). OSDI 1999.
Not read, so not relied on: Kremlin (PLDI 2011), which reportedly predicts parallel speedup and must be checked before psync claims its predictor is new; Hollingsworth and Miller’s slack; the Asynchronizer tools for Android and C#; Rudra’s paper.