Skip to content

Instantly share code, notes, and snippets.

@rfk
Created May 20, 2020 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfk/d5a8d2c769cb9aea3fc9c8597fdf6e4a to your computer and use it in GitHub Desktop.
Save rfk/d5a8d2c769cb9aea3fc9c8597fdf6e4a to your computer and use it in GitHub Desktop.
import sys
from collections import defaultdict
with open(sys.argv[1]) as f:
lines = (ln.strip() for ln in f)
# Skip headers.
assert next(lines).startswith("File")
# Sum up serde-related things vs total.
totalSize = 0
sizeByCrate = defaultdict(int)
sizeFromSerdeByCrate = defaultdict(int)
for ln in lines:
# The output ends with a summary, which isn't useful to us.
if ".text section size" in ln:
break
(_, _, size, crate, name) = ln.split(None, 4)
if size.endswith("KiB"):
size = int(float(size[:-3]) * 1024)
elif size.endswith("B") and size[-2].isdigit():
size = int(size[:-1])
else:
assert False, "Unable to parse size {!r}".format(size)
# Ignore symbols from non-rust dependencies, and things that won't
# be relevant to us when vendoring into Firefox..
if crate in ("[Unknown]", "std", "nss_sys"):
continue
totalSize += size
sizeByCrate[crate] += size
if "serde" not in crate and "serde" in name.lower():
sizeFromSerdeByCrate[crate] += size
# What's the damage?
for (size, crate) in sorted(((size, crate) for (crate, size) in sizeByCrate.items()), reverse=True):
print("{:<6} of {:<6} bytes ({:.2f}%) come from {!r}".format(
size,
totalSize,
(size / totalSize) * 100,
crate,
))
if sizeFromSerdeByCrate[crate]:
print(" of which {:<6} bytes ({:.2f}%) from serde derives".format(
sizeFromSerdeByCrate[crate],
(sizeFromSerdeByCrate[crate] / size) * 100,
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment