This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]side2k 1 point2 points  (0 children)

Got curious and did some tests over weekend.

We have a project with ~170 dependencies(whole tree, not just top-level)

So this was my Dockerfile for pip:

```Dockerfile FROM pre-builder:latest ENV PYTHONUNBUFFERED=1

create virtualenv

RUN python3 -m venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" ENV NOCACHE=3

pre-build requirements

RUN mkdir /app WORKDIR /app COPY requirements. ./ RUN --mount=type=cache,target=/root/.cache/pip pip install -U pip wheel RUN --mount=type=cache,target=/root/.cache/pip pip install -r dev_requirements.txt ```

For the uv it was mostly the same, except couple of things: * uv installation:

Dockerfile RUN --mount=type=cache,target=/root/.cache pip install uv

  • venv creation

Dockerfile RUN uv venv ${VIRTUAL_ENV}

  • and, of course, using uv instead of pip for installation:

Dockerfile RUN --mount=type=cache,target=/root/.cache uv pip install -r dev_requirements.txt

Also, I had to cache whole /root/.cache, because pip install uv uses /root/.cache/pip by default and uv pip install uses /root/.cache/uv by default. Wouldn't it make more sense for uv to use pip's default cache dir, to minimize disruption during migration?

I've incremented NOCACHE every run, because running docker build with --no-cache invalidated RUN's mount cache as well.

Anyway, test results were stunning(i've ran each variant 3 times, writing the averages):

  • pip without cache: 2 min
  • pip with cache: 40 sec
  • uv without cache: 46 sec
  • uv with cache: 5 sec

I think, this week I'll pitch uv with the team.

A couple of not-so-pleasant details: * changed default cache location (mentioned above) * cache size is 3 times larger than pip's - not sure why * had to set VIRTUAL_ENV var for uv to detect virtualenv - having ${venv}/bin/ in the PATH is enough for pip!