Skip to content

Example: documenting an upstream contribution end to end

· 2 min read

Every article on this site pairs a written explanation with the data and code behind it, plus a record of any upstream change it came from — so a reader can check the claim, reuse the material, and see who did the work.

This article exists to show the format. It is a real structure with placeholder content — replace it with your own work, or delete the folder entirely.

Why this format

A claim is only useful if someone can check it. Every article here is built to carry three things alongside the prose:

  1. The data, as a real file you can download from this domain.
  2. The code that produced it, pinned to specific versions.
  3. The upstream change, if the work resulted in one, linked to the merged pull request.

That combination is also what makes the work findable. A search engine reading this page sees structured records for the dataset, the source contribution and the author, all pointing at the same identity — not just a wall of text.

The change

The original file walker was sequential:

def walk(root: Path) -> list[Path]:
    files = []
    for entry in root.rglob("*"):
        if entry.is_file() and not is_ignored(entry):
            files.append(entry)
    return files

On a repository with 80,000 files this spent almost all of its time blocked on stat calls. Replacing it with a bounded pool of workers, one subtree per task, removed most of that:

def walk(root: Path, workers: int = 8) -> list[Path]:
    subtrees = [p for p in root.iterdir() if p.is_dir()]
 
    with ThreadPoolExecutor(max_workers=workers) as pool:
        results = pool.map(_walk_subtree, subtrees)
 
    files = [f for group in results for f in group]
    files.extend(p for p in root.iterdir() if p.is_file() and not is_ignored(p))
    return sorted(files)

Results

RepositoryFilesBefore (s)After (s)Speedup
small-lib3120.40.41.0x
mid-service4,2012.90.83.6x
large-monorepo81,45540.26.16.6x

Median across all twelve repositories was 6.6x. Full results are in the attached CSV; the script that produced them is attached too.

What to do with this file

Copy the folder, rename it, and edit the frontmatter. The fields are documented in content/articles/README.md. The only required ones are title, description, date and category — everything else is optional and simply does not render when omitted.

Upstream contributions

Work by Alfred Kolakkal that was merged into these repositories.

Data & code

Everything used to produce this article. Free to download, reuse and check.

Frequently asked questions

How much faster is the parallel file walker?

On the twelve repositories tested, median cold-start indexing time fell from 40.2 seconds to 6.1 seconds — about 6.6x. The gain is largest on repositories with many small files and negligible on repositories under roughly 500 files.

Does the change affect correctness?

No. The walker produces the same file set in the same order; only the traversal is parallelised. A follow-up change was needed to handle symlink cycles, which the sequential walker had avoided by accident.

Can I reproduce these numbers?

Yes. The benchmark script and the raw results are attached to this article, and the script pins the exact commit of each repository it tests.

Share
1

1 comment

Corrections and additions are welcome.

  1. ALPHA ALCHEMY

    excellent, example for the test run.

    1

Leave a comment

You need an account to comment. Reading, voting counts and sharing stay open to everyone.

Sign in to comment