refactor(Klipper): trim klipper git clone to only latest history #418

Open
nberardi wants to merge 1 commits from nberardi/patch-1 into master
nberardi commented 2024-01-01 21:09:50 +01:00 (Migrated from github.com)

I was receiving the following error on my Raspberry Pi Zero 2 W during the installation of Klipper, while running the 64-bit lite version of Raspberry Pi OS (bookworm).2

error: RPC failed; curl 92 HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)

I tracked this down to a likely low memory issue due to the size of the git repo. I was able to correct for this issue, by only downloading the tip of the history of the Klipper repo during install by setting --depth 1 in the git clone command. This resulted in a roughly 13x reduction in the size of the downloaded repo and allowed me to continue my install without issue using KIAUH.

I was receiving the following error on my Raspberry Pi Zero 2 W during the installation of Klipper, while running the 64-bit lite version of Raspberry Pi OS (bookworm).2 ``` error: RPC failed; curl 92 HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1) ``` I tracked this down to a likely low memory issue due to the size of the git repo. I was able to correct for this issue, by only downloading the tip of the history of the Klipper repo during install by setting `--depth 1` in the `git clone` command. This resulted in a roughly 13x reduction in the size of the downloaded repo and allowed me to continue my install without issue using KIAUH.
dw-0 commented 2024-01-01 23:05:00 +01:00 (Migrated from github.com)

I think this might be a good change. I tested it myself and there is roughly a saving of 140mb we don't need to download, just 10mb instead.

Though, there is another feature of KIAUH which needs to be refactored a little bit if we implement that change. There is a "rollback" feature, where its possible to enter a number and klipper gets "rolled back" (basically a hard reset) by that amount of commits. https://github.com/dw-0/kiauh/blob/master/scripts/rollback.sh#L71

If we have "no history" or a very short one, and for some reason someone want to rollback a larger amount of commits than available in the history, git will throw an error. so it may require refactoring that workflow, so that the size of the history is checked before the hard reset is executed.

I think this might be a good change. I tested it myself and there is roughly a saving of 140mb we don't need to download, just 10mb instead. Though, there is another feature of KIAUH which needs to be refactored a little bit if we implement that change. There is a "rollback" feature, where its possible to enter a number and klipper gets "rolled back" (basically a hard reset) by that amount of commits. https://github.com/dw-0/kiauh/blob/master/scripts/rollback.sh#L71 If we have "no history" or a very short one, and for some reason someone want to rollback a larger amount of commits than available in the history, git will throw an error. so it may require refactoring that workflow, so that the size of the history is checked before the hard reset is executed.
ElectricalBoy commented 2024-01-21 09:02:42 +01:00 (Migrated from github.com)

Doing a shallow clone is more expensive than doing a full clone in the long term (ref: https://github.com/CocoaPods/CocoaPods/issues/4989#issuecomment-193772935, https://github.com/Homebrew/brew/pull/9383).

Sure - Kilpper repo will (almost certainly) never get as much traffic as the two repos linked above (nor will its size grow as big), but my point still stands. Doing a full clone initially becomes cheaper in the long run (especially if you run updates).

Doing a shallow clone is more expensive than doing a full clone in the long term (ref: https://github.com/CocoaPods/CocoaPods/issues/4989#issuecomment-193772935, https://github.com/Homebrew/brew/pull/9383). Sure - Kilpper repo will (almost certainly) never get as much traffic as the two repos linked above (nor will its size grow as big), but my point still stands. Doing a full clone initially becomes cheaper in the long run (especially if you run updates).
nberardi commented 2024-01-21 14:23:39 +01:00 (Migrated from github.com)

@ElectricalBoy more expensive than not being able to pull the repo on my Raspberry Pi Zero 2W? 😀

There are other options that could have been tried, but this was the cleanest code change that allowed me to keep moving on my install.

@ElectricalBoy more expensive than not being able to pull the repo on my Raspberry Pi Zero 2W? 😀 There are [other options](https://stackoverflow.com/questions/59282476/error-rpc-failed-curl-92-http-2-stream-0-was-not-closed-cleanly-protocol-erro) that could have been tried, but this was the cleanest code change that allowed me to keep moving on my install.
ElectricalBoy commented 2024-01-21 15:08:56 +01:00 (Migrated from github.com)

I see the change of the default behavior to introduce a long-term side-effect as a regression.

Yes, I do acknowledge that doing a shallow clone does act as a short-term solution for this specific problem, especially on lower-end devices (i.e., RPi Zeros). However, this comes at a cost of introducing a regression on the majority of use cases (i.e., normal RPis). This, I believe, shows that the cleanest code is not the cleanest solution for a problem.

What I think should happen instead is keeping the default behavior to do a full clone but adding an option to do a shallow clone (which can possibly be set in the advanced menu).

I see the change of the default behavior to introduce a long-term side-effect as a regression. Yes, I do acknowledge that doing a shallow clone _does_ act as a short-term solution for this specific problem, especially on lower-end devices (i.e., RPi Zeros). However, this comes at a cost of introducing a regression on the majority of use cases (i.e., normal RPis). This, I believe, shows that the cleanest code is __not__ the cleanest solution for a problem. What I think should happen instead is keeping the default behavior to do a full clone but _adding_ an option to do a shallow clone (which can possibly be set in the advanced menu).
dw-0 commented 2024-01-21 16:59:43 +01:00 (Migrated from github.com)

Doing a shallow clone is more expensive than doing a full clone in the long term

I understand it that way, that it would be more expensive on githubs side than on the client side?

I see the change of the default behavior to introduce a long-term side-effect as a regression.
[...]
However, this comes at a cost of introducing a regression on the majority of use cases

Can you elaborate? What would be an actual regression?

> Doing a shallow clone is more expensive than doing a full clone in the long term I understand it that way, that it would be more expensive on githubs side than on the client side? > I see the change of the default behavior to introduce a long-term side-effect as a regression. > [...] > However, this comes at a cost of introducing a regression on the majority of use cases Can you elaborate? What would be an actual regression?
dw-0 commented 2024-02-04 17:31:21 +01:00 (Migrated from github.com)

@ElectricalBoy any more input on this? Especially in regards to my previous questions?

@ElectricalBoy any more input on this? Especially in regards to my previous questions?
ElectricalBoy commented 2024-04-29 07:12:27 +02:00 (Migrated from github.com)

I understand it that way, that it would be more expensive on githubs side than on the client side?

If the user needs to checkout an old commit (that is not available via the shallow tree) then fetching the giant tree eventually becomes inevitable - and this connects to my old regression argument, as this introduces the new overhead when rolling back.

Although I am mildly annoyed by the regression, considering the # of times a rollback is needed in general this seems like a reasonable compromise after giving some more thought. Plus it seems that Git handles this better in general than how it did few years back.

P.s.: Sorry for getting back so late - had other commitments that needed my attention.

> I understand it that way, that it would be more expensive on githubs side than on the client side? If the user needs to checkout an old commit (that is not available via the shallow tree) then fetching the giant tree eventually becomes inevitable - and this connects to my old regression argument, as this introduces the new overhead when rolling back. Although I am mildly annoyed by the regression, considering the # of times a rollback is needed in general this seems like a reasonable compromise after giving some more thought. Plus it seems that Git handles this better in general than how it did few years back. P.s.: Sorry for getting back so late - had other commitments that needed my attention.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin nberardi/patch-1:nberardi/patch-1
git checkout nberardi/patch-1
Sign in to join this conversation.