Skip to content

CSV conversion scales quadratically with leading blank lines #2449

Closed

Description

@ROTl24

CSV conversion slows down quadratically when a file contains a long run of blank lines before the header or immediately after it. The output is correct, but trimming those rows takes most of the conversion time.

This script uses only in-memory CSV data:

import io
import statistics
import time

from markitdown import MarkItDown, StreamInfo

converter = MarkItDown(enable_plugins=False)
info = StreamInfo(extension=".csv", charset="utf-8")

for count in (25_000, 50_000, 100_000):
    data = b"\n" * count + b"name,value\nexample,1\n"
    samples = []
    for _ in range(3):
        start = time.perf_counter()
        result = converter.convert_stream(io.BytesIO(data), stream_info=info)
        samples.append(time.perf_counter() - start)
    print(count, statistics.median(samples))

On Windows with Python 3.13.15 and MarkItDown 0.1.8b1 (source commit b59e064), the medians were 0.0296 s, 0.1170 s, and 0.6953 s. These are synthetic inputs, not timings from a production workload.

Since these inputs differ only in the number of blank lines, I'd expect conversion time to grow roughly linearly. _trim_outer_blank_rows currently calls pop(0) or pop(1) for every blank row, shifting the remaining list each time. Removing each blank run in one slice avoids that repeated work while preserving the output.

Activity

  1. afourney commented on Sep 10, 2026

    @afourney
    Member

    Good point. We can do better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions