simplex-chat / simplex-chat/simplexmq

Consider streaming decryption/write path to reduce peak memory usage for large files

Open
#1,776 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haskell
Stars
847
Forks
111
Avg merge
3d 11h
Merged PRs (30d)
9

Description

I noticed the current download verification/decryption flow buffers the full encrypted file into memory before decrypting.

Current flow appears to:

accumulate encrypted chunks in chunks[]
concatenate them via concatBytes(...chunks)
allocate another full plaintext buffer with new Uint8Array(pLen)

This can significantly increase peak memory usage for large files, especially on mobile browsers.

The crypto layer itself already seems stream-capable (sbInit, sbDecryptChunk, incremental Poly1305 state), so I was wondering whether a more streaming-oriented architecture could be considered in the future.

Possible direction:

download chunk
→ decrypt incrementally
→ write plaintext directly to OPFS/temp storage
→ finalize/verify auth tag at end

This could reduce peak RAM usage from approximately full-file-size multiples down to near chunk-size memory usage.

I understand there are important tradeoffs around:

final authentication validation
temporary storage cleanup on auth failure
padding/header parsing
resumable download behavior

So I wanted to ask whether this direction would be desirable before experimenting with an implementation.

Contributor guide

No contributing guide indexed for this repository

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 by locating the download verification/decryption flow that accumulates chunks[], calls concatBytes(...chunks), and allocates Uint8Array(pLen), then read the streaming primitives sbInit and sbDecryptChunk. The issue does not define an implementation scope; clarify the architecture and acceptance criteria for incremental writes, final authentication failure cleanup, padding/header parsing, and resumable downloads before coding.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
cryptography, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.