docker icon indicating copy to clipboard operation
docker copied to clipboard

Update replace-placeholder.sh

Open dvusboy opened this issue 1 year ago • 1 comments

Speed up the replacement loop

  • only look at files with the "$FROM" pattern

dvusboy avatar Sep 21 '24 00:09 dvusboy

A quick test with v4.5.3 shows these results:

Current:

root@4f3f81c57237:/calcom/apps# FROM='http://localhost:3000'; TO='https://cal.example.com'; time find web/.next/ web/public/ -type f | while read file; do sed -i "s|$FROM|$TO|g" "$file"; done

real	1m22.762s
user	0m52.981s
sys	0m44.544s

New:

root@a6f1f3600029:/calcom/apps# FROM='http://localhost:3000'; TO='https://cal.example.com'; time for file in $(egrep -r -l "$FROM" web/.next/ web/public/); do sed -i -e "s|$FROM|$TO|g" "$file"; done

real	0m3.356s
user	0m1.487s
sys	0m1.958s

dvusboy avatar Sep 21 '24 00:09 dvusboy

Optimization generally LGTM, but without knowing this project well enough, I'd be worried how you got to so many files in these directories that a simple looped sed ends up needing 1m22 to process.

@dvusboy Did you observe these times on custom builds only? Did you maybe have some kind of leftovers from older builds locally that got copied into the final image?

codablock avatar Apr 10 '25 22:04 codablock

Well, 2 points:

  • To get the timing difference, I just run the script in-place, changed and not changed. It's pretty easy to do by overriding CMD to the Docker image with /bin/bash with docker run.
  • It is pretty obvious that the changes would speed things up by reducing the number of files needing changes. The extent was a little surprising.

I didn't change much to the sed line, just explicitly prefixing the script with -e.

dvusboy avatar Apr 11 '25 00:04 dvusboy

Ah ok, so you ran it outside of the Docker build? That would explain the huge amount of time needed initially (I assume a local build ends up having much more/larger files then a Docker build).

As said, the optimisation itself is a LGTM.

codablock avatar Apr 11 '25 07:04 codablock