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

Evaluate dumping .lib.json without indentantion #315

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/jsonsize.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: JSON size opt

on:
push:

jobs:

json:
runs-on: ubuntu-latest

steps:

- uses: actions/checkout@v2

- run: |
for d in ./libraries/*; do
git submodule update --init "$d"/latest
done

- run: ./jsonsize.py
54 changes: 54 additions & 0 deletions jsonsize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3

from pathlib import Path
from json import dumps, loads

ROOT = Path(__file__).resolve().parent / 'libraries'

def printSize(key, origSize, dumpSize):
_GB = (1024 * 1024 * 1024)
print(
f'{key}:',
origSize / _GB, 'GB',
'->',
dumpSize / _GB, 'GB',
f"[{100*dumpSize/origSize}%]" if origSize != 0 else ""
)

origSize = {}
dumpSize = {}

# For each library
for _dir in ROOT.iterdir():
_dname = _dir.name

# Check latest version only
_verdir = _dir / 'latest'

# Initialize size counters
origSize[_dname] = 0
dumpSize[_dname] = 0

# For each '*.lib.json' file (recursively)
for item in _verdir.glob('**/*.lib.json'):
# Get and accumulate size
origSize[_dname] += item.stat().st_size
# Read and dump
_dump = Path(str(item) + '.dump')
_dump.write_text(dumps(loads(item.read_bytes())))
# Get and accumulate dump size
dumpSize[_dname] += _dump.stat().st_size
# Remove dump
_dump.unlink()

# Print summary
_GB = (1024 * 1024 * 1024)
origTotal = 0
dumpTotal = 0
for key, val in origSize.items():
_dump = dumpSize[key]
printSize(key, val, _dump)
origTotal += val
dumpTotal += _dump

printSize('Total', origTotal, dumpTotal)