Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save 1MB by not using charmbracelet/log #119

Merged
merged 4 commits into from
Sep 25, 2024
Merged

Save 1MB by not using charmbracelet/log #119

merged 4 commits into from
Sep 25, 2024

Conversation

Mic92
Copy link
Member

@Mic92 Mic92 commented Sep 24, 2024

Adding nixos-facter tipped us over the edge for 1GB RAM in nixos-anywhere. Another upside is that less dependencies means less updates.

pkg/virt/detect_vm_xen.go Outdated Show resolved Hide resolved
pkg/virt/detect_vm_xen.go Outdated Show resolved Hide resolved
Adding nixos-facter tipped us over the edge for 1GB RAM in
nixos-anywhere. Another upside is that less dependencies means
less updates.
@Mic92
Copy link
Member Author

Mic92 commented Sep 24, 2024

Now we are at half the binary size that we started with.

@brianmcgee
Copy link
Collaborator

I hope you started by trying to rip things out of nixos-anywhere before labotomizing nixos-facter 😂

To be fair we didn't really need the log and flag features, they're my go to when starting out.

What kinda max binary size do we have to work with if we aren't gonna blow nixos-anywhere's budget in the future?

@Mic92
Copy link
Member Author

Mic92 commented Sep 24, 2024

I hope you started by trying to rip things out of nixos-anywhere before labotomizing nixos-facter 😂

Oh yeah, we did optimize hard: https://github.com/nix-community/nixos-images/blob/8650b1df8f965bf33dec79351646e19406ff9d50/nix/noninteractive.nix#L17

https://github.com/nix-community/nixos-images/blob/8650b1df8f965bf33dec79351646e19406ff9d50/nix/zfs-minimal.nix#L6

Ideally we could get rid of perl... but there is still nixos-generate-config.

To be fair we didn't really need the log and flag features, they're my go to when starting out.

What kinda max binary size do we have to work with if we aren't gonna blow nixos-anywhere's budget in the future?

It's only after I added nixos-facter, when nixos tests starting to go out-of-memory. It might have just put it over the edge. I have to see when we get back into the safe zone.

@brianmcgee
Copy link
Collaborator

These changes take the binary from 5M down to 2.6M.

I'm mindful of #117, which I'll look at in the next day or two and consider what changes it might require.

Is there an easy way to test if I've blown the nixos-anywhere RAM budget? A representative test to run or something?

@brianmcgee
Copy link
Collaborator

It's only after I added nixos-facter, when nixos tests starting to go out-of-memory. It might have just put it over the edge. I have to see when we get back into the safe zone.

Just re-read this and realised you're still unsure about what the budget might be. I'll let you keep working through it.

@brianmcgee brianmcgee self-assigned this Sep 24, 2024
@Mic92
Copy link
Member Author

Mic92 commented Sep 25, 2024

I just gave us more breathing space by overriding python with python minimal in various filesystem tools. I would say libraries that add hardware detection should be fine. In the case of lsusb, I briefly studied the code, and I think it would be hard to find a library that handles all the edge cases that it handles. So I would instead suggesting parsing the output of lsusb -v. But in any case having a small binary will make it an easier sell later when we want to replace nixos-generate-config in NixOS as well.

@Mic92
Copy link
Member Author

Mic92 commented Sep 25, 2024

This now is an easier to read --help:

nixos-facter [flags]
Hardware report generator

Usage:
  nixos-facter [flags]

Flags:
  --ephemeral          capture all ephemeral properties e.g. swap, filesystems and so on
  -h, --help           help for nixos-facter
  -o, --output string  path to write the report
  --swap               capture swap entries
  --hardware strings   Hardware items to probe.
                       Default: memory,pci,net,serial,cpu,bios,monitor,scsi,usb,prom,sbus,sys,sysfs,udev,block,wlan
                       Possible values: memory,pci,isapnp,net,floppy,misc,misc_serial,misc_par,misc_floppy,serial,cpu,bios,monitor,mouse,scsi,usb,usb_mods,adb,modem,modem_usb,parallel,parallel_lp,parallel_zip,isa,isa_isdn,isdn,kbd,prom,sbus,braille,braille_alva,braille_fhp,braille_ht,ignx11,sys,bios_vbe,isapnp_old,isapnp_new,isapnp_mod,braille_baum,manual,fb,veth,pppoe,scan,pcmcia,fork,parallel_imm,s390,cpuemu,sysfs,s390disks,udev,block,block_cdrom,block_part,edd,edd_mod,bios_ddc,bios_fb,bios_mode,input,block_mods,bios_vesa,cpuemu_debug,scsi_noserial,wlan,bios_crc,hal,bios_vram,bios_acpi,bios_ddc_ports,modules_pata,net_eeprom,x86emu,max,lxrc,all

This is now nicer than what we had before.
@brianmcgee
Copy link
Collaborator

I briefly studied the code, and I think it would be hard to find a library that handles all the edge cases that it handles. So I would instead suggesting parsing the output of lsusb -v. But in any case having a small binary will make it an easier sell later when we want to replace nixos-generate-config in NixOS as well.

Good to know. I'm going to give this some focused attention today or tomorrow.

@brianmcgee brianmcgee merged commit 4a180aa into main Sep 25, 2024
14 checks passed
@brianmcgee brianmcgee deleted the cleanup branch September 25, 2024 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants