Skip to content
This repository was archived by the owner on Oct 29, 2025. It is now read-only.

Conversation

@dvusboy
Copy link
Contributor

@dvusboy dvusboy commented Sep 21, 2024

Speed up the replacement loop

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

Speed up the replacement loop

* only look at files with "$FROM" pattern
@dvusboy
Copy link
Contributor Author

dvusboy commented Sep 21, 2024

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 dvusboy changed the title Update replace-placeholder.sh Update replace-placeholder.sh for much faster startup Oct 31, 2024
@codablock
Copy link

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?

@dvusboy
Copy link
Contributor Author

dvusboy commented Apr 11, 2025

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.

@codablock
Copy link

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.

@PeerRich PeerRich merged commit 50dc054 into calcom:main Apr 30, 2025
@dvusboy dvusboy deleted the replace-placeholder-speedup branch April 30, 2025 19:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants