leanprover / leanprover/lean4

Unable to write to a file with an offset

Open
#12,931 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Description

I need to be able to write to any part of a file with multiple coroutines in parallel.

AI hallucinated IO.FS.Handle.seek, which would definitely solve the problem if it existed.

Context

I recently wrote an XorEncrypt project in 3 languages:

  • Go 1.25.7
  • Lean 4.28.0
  • Python 3.13.12

2 had the required function:

All 3 implementations used 1 worker coroutine per available logical CPU core.
Go and Python workers read, calculated, and wrote in parallel. Lean used only pipeline concurrency for its workers: 1 reading coroutine sequentially read to create jobs; those jobs were passed to workers for calculation; 1 writer coroutine sequentially wrote the results.

A recent benchmark with 931 MiB files:
Go : 1760421648 B/s
Lean4 : 1025278972 B/s
Python: 216356205 B/s

Steps to Reproduce
  1. Read 21.5. Files, File Handles, and Streams, find no corresponding method exists.
  2. Ask multiple AI, all of which hallucinate or say it is impossible.
  3. File this bug report if it does not exist; else, 👍🏻 this bug report.

Expected behavior: Lean 4 is the fastest! 🎉

Actual behavior: [Lean 4]'s speed ≤ 0.58241 × Go's speed.

Versions
~/Git/XorEncrypt via 🐹 v1.25.7 via 🐍 v3.13.12 
❯ kinfo
Operating System: NixOS 26.05
KDE Plasma Version: 6.6.2
KDE Frameworks Version: 6.24.0
Qt Version: 6.10.2
Kernel Version: 6.19.6 (64-bit)
Graphics Platform: Wayland
Processors: 20 × 12th Gen Intel® Core™ i9-12900HK
Memory: 64 GiB of RAM (62.5 GiB usable)
Graphics Processor 1: Intel® Iris® Xe Graphics
Graphics Processor 2: NVIDIA GeForce RTX 3050 Ti Laptop GPU

~/Git/XorEncrypt via 🐹 v1.25.7 via 🐍 v3.13.12 
❯ lean --version && lake --version
Lean (version 4.28.0, commit v4.28.0, Release)
Lake version 5.0.0-src+v4.28.0 (Lean version 4.28.0)
Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the referenced “21.5. Files, File Handles, and Streams” documentation and inspect the existing IO file-handle APIs, especially the absence of IO.FS.Handle.seek. Compare the requested capability with the linked Go WriteAt and Python pwrite behavior. Done means the project has a supported way to write at arbitrary file offsets from concurrent workers, with its API and concurrency behavior documented.

Written by the indexing model from the issue text.

Assessment

Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.