σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
Apache Arrow skill›Module 2 · Memory layout, sharing and files›Topic 2.3·~40 minAdvanced

IPC and Feather files

Skill positionModule 2 of 3 · Topic 3 of 4
2.3 IPC and Feather files
—Lab score— / 100Total XP—Streak—
Lecture0% read

3 min readCode examples: 3

  1. 01The idea in plain words
  2. 02A file: save it, then read it mapped or not
  3. 03A stream: batches over time
  4. 04What the tasks ask

Saving a table normally means converting it: a CSV is text, a pickle is Python's own format. Arrow's file format does neither. It writes the buffers as they sit in memory, so loading is just pointing at the bytes. A multi-gigabyte tick table can open in milliseconds because nothing is parsed, and several processes can map the same file and share one copy in the operating system's cache.

01

The idea in plain words

Where we are. Topic 5 shared memory between libraries inside one process. This topic extends the same idea to disk and to other processes: the IPC format is the buffers of topic 4 with a little framing around them. The Parquet skill covered the other file format, which compresses harder and is cheaper to store; IPC is the one to pick when speed to open matters most.

DefinitionMemory mapping

Asking the operating system to expose a file as if it were part of the program's memory. Pages load only when touched and are shared between processes, so a big file opens at once and costs no extra RAM of its own.

02

A file: save it, then read it mapped or not

write_feather writes the Feather version 2 file, which is simply an IPC file; lz4 and zstd compress each buffer and trade open speed for size. read_ipc_file(path, True) maps the file and builds the table on its pages, so the numbers below show no new allocation, while a normal read copies every byte into freshly allocated memory. A compressed file cannot be used in place: it must be decompressed first.

main.pyPython
# Three Feather files of the same table: sizes by codecfor codec in ["uncompressed", "lz4", "zstd"]:    print(f"{codec:12} {write_feather(table, codec + '.arrow', codec):>9,} bytes")
uncompressed 1,711,442 bytes
lz4          1,111,738 bytes
zstd           911,258 bytes
main.pyPython
# Read the uncompressed file mapped and then normally, and watch Arrow's allocation counterbefore = pa.total_allocated_bytes()mapped = read_ipc_file("uncompressed.arrow", True)print("mapped: equal", mapped.equals(table), "| new allocation:", pa.total_allocated_bytes() - before, "bytes")before = pa.total_allocated_bytes()copied = read_ipc_file("uncompressed.arrow", False)print("copied: equal", copied.equals(table), "| new allocation:", f"{pa.total_allocated_bytes() - before:,}", "bytes")
mapped: equal True | new allocation: 0 bytes
copied: equal True | new allocation: 1,710,592 bytes
03

A stream: batches over time

A file needs a footer, so it can only be finished once everything has been written. A stream has no footer: a schema, then batches in order, readable as they arrive. That is the shape for a socket or a pipe between two processes, or for a tick feed. count_stream_rows reads one batch at a time and never holds the whole stream, which is the point of the format.

main.pyPython
# The bars as an IPC stream in batches of 10,000 rows, then read back one batch at a timewritten = write_stream(table, "bars.stream", 10000)batches, rows = count_stream_rows("bars.stream")print(f"{os.path.getsize('bars.stream'):,} bytes in the stream file | {written} batches written | read back: {batches} batches, {rows} rows")
1,710,872 bytes in the stream file | 5 batches written | read back: 5 batches, 33493 rows
IPC or Parquet?

IPC opens fastest and can be used in place, but its files are larger. Parquet is smaller and can skip data by column, row group and statistics, but it has to be decoded. Use IPC for hot data that many processes read on one machine, and for passing batches between processes; use Parquet for the long-term lake.

04

What the tasks ask

  1. 1
    `write_feather` and `read_ipc_file`feather.write_feather(table, path, compression=...); read with ipc.open_file(source).read_all(), where source is pa.memory_map(path, "r") or the path.
  2. 2
    `write_stream` and `count_stream_rows`ipc.new_stream(sink, schema) and write_batch for each to_batches(...) slice; ipc.open_stream(source) and iterate it.

Key takeaways

  • The file is the memory IPC writes buffers as they are, so reading needs no parsing.
  • Map it, share it A mapped file costs no extra RAM and is shared between processes.
  • Streams for data in motion Batch by batch, no footer. Next: dictionaries and timestamps.
Quick check
Why does reading an uncompressed IPC file with memory mapping allocate almost no new memory?
Pick an answer.

Lab · what's graded

4 tasks · 100 pts
  • Save a Feather file: write_feather25 pts
  • Read it, mapped or not: read_ipc_file25 pts
  • Write a stream of batches: write_stream25 pts
  • Read it batch by batch: count_stream_rows25 pts
Explorer · lab-6-1
▾ lab-6-1
▾ data
…
bash · in-browser
learner@quantcraft:~/lab-6-1$
Python not loaded yetPythonLn 1, Col 1Spaces: 4UTF-8

Reset this topic?

Everything in lab-6-1 goes back to the starter files and the terminal is cleared. Your current solution will be lost — this can't be undone.

Will be reset
  • main.py → starter code
  • Terminal history and test output
  • Unsubmitted changes
Will be kept
  • Best lab score
  • Your XP and streak
  • Lecture progress and notes