libgit2 / libgit2/libgit2

Perf suggestion for crlf handling

Open
#3,212 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
10.6k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

I haven't measured this but....

As long a the crlf filtering is loading the entire blob/file into a buffer, there are some opportunities here for perf gains.

In git_buf_text_is_binary() we examine the entire file. While there we could count the number of CRLFs, and plain LFs and return those sums. We should be able to use those sums in git_buf_text_gather_stats(). Or combine those 2 routines into 1. Then in git_buf_text_lf_to_crlf() add this delta "(count_crlf - count_lf)" as padding to the amount of reserved space in the destination buffer so that the memcpy loop doesn't need to realloc as the file is being converted.

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 by reading git_buf_text_is_binary(), git_buf_text_gather_stats(), and git_buf_text_lf_to_crlf() to understand their current buffer and line-ending handling. Measure the existing behavior before evaluating the suggested combined counts and padding; done means conversion avoids unnecessary reallocations without changing the resulting text.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, git
Domain
performance
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
43/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.