|
| 1 | +# JSON Optimization Plan for webhooks.json and objects.json |
| 2 | + |
| 3 | +## Current State |
| 4 | + |
| 5 | +| File | Source Size | Minified Size | |
| 6 | +|------|-------------|---------------| |
| 7 | +| webhooks.json | 828 KB | 265 KB | |
| 8 | +| objects.json | 476 KB | 199 KB | |
| 9 | +| **Total** | **1,304 KB** | **464 KB** | |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## Optimization Approaches |
| 14 | + |
| 15 | +### 1. Short Property Names (~80 KB savings, ~17% reduction) |
| 16 | + |
| 17 | +Replace verbose property names with single-character keys in the minified output. |
| 18 | + |
| 19 | +| Property | Current | Short | Occurrences | Savings | |
| 20 | +|----------|---------|-------|-------------|---------| |
| 21 | +| `name` | 4 chars | `n` | 15,507 | 46 KB | |
| 22 | +| `description` | 11 chars | `d` | 1,716 | 17 KB | |
| 23 | +| `childParamsGroups` | 17 chars | `c` | 949 | 15 KB | |
| 24 | +| `bodyParameters` | 14 chars | `b` | 141 | 2 KB | |
| 25 | +| | | | **Total** | **~80 KB** | |
| 26 | + |
| 27 | +**Result: 464 KB → ~384 KB** |
| 28 | + |
| 29 | +**Complexity:** Low - just rename keys when generating minified version |
| 30 | + |
| 31 | +--- |
| 32 | + |
| 33 | +### 2. Array-Based Structure (~79 KB savings, ~17% reduction) |
| 34 | + |
| 35 | +Replace objects with positional arrays to eliminate all property name overhead. |
| 36 | + |
| 37 | +**Current format:** |
| 38 | +```json |
| 39 | +{"name":"url","description":"The URL"} |
| 40 | +``` |
| 41 | + |
| 42 | +**Array format:** |
| 43 | +```json |
| 44 | +["url","The URL"] |
| 45 | +``` |
| 46 | + |
| 47 | +Position: `[0]=name, [1]=description, [2]=childParamsGroups` |
| 48 | + |
| 49 | +| Object Type | Count | Savings per Object | Total Savings | |
| 50 | +|-------------|-------|-------------------|---------------| |
| 51 | +| name only | 5,459 | 10 bytes | 53 KB | |
| 52 | +| name + description | 603 | 24 bytes | 14 KB | |
| 53 | +| name + children | 303 | 25 bytes | 7 KB | |
| 54 | +| name + desc + children | 98 | 40 bytes | 4 KB | |
| 55 | +| | | **Total** | **~79 KB** | |
| 56 | + |
| 57 | +**Result: 464 KB → ~385 KB** (or ~305 KB combined with approach 1) |
| 58 | + |
| 59 | +**Complexity:** Medium - requires updating reader code to handle array format |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +### 3. String Interning for Values (~40 KB savings, ~9% reduction) |
| 64 | + |
| 65 | +Create a string table for frequently repeated values and reference by index. |
| 66 | + |
| 67 | +**Top repeated values in objects.json:** |
| 68 | + |
| 69 | +| Value | Occurrences | Bytes per occurrence | Total overhead | |
| 70 | +|-------|-------------|---------------------|----------------| |
| 71 | +| `url` | 256 | 3 → 1-2 | 0.5 KB | |
| 72 | +| `id` | 250 | 2 → 1-2 | minimal | |
| 73 | +| `node_id` | 244 | 7 → 1-2 | 1.2 KB | |
| 74 | +| `html_url` | 210 | 8 → 1-2 | 1.3 KB | |
| 75 | +| `name` | 208 | 4 → 1-2 | 0.4 KB | |
| 76 | +| ... and 418 more unique values | | | | |
| 77 | + |
| 78 | +**Format:** |
| 79 | +```json |
| 80 | +{ |
| 81 | + "strings": ["url", "id", "node_id", "html_url", ...], |
| 82 | + "data": [[0], [1, "Unique ID"], ...] // reference by index |
| 83 | +} |
| 84 | +``` |
| 85 | + |
| 86 | +**Estimated savings:** ~40 KB |
| 87 | + |
| 88 | +**Complexity:** High - requires string table lookup at runtime |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +### 4. Deduplicate Identical Subtrees (~30-50 KB savings, ~7-11% reduction) |
| 93 | + |
| 94 | +Many objects have identical `childParamsGroups` structures. Reference them once. |
| 95 | + |
| 96 | +Example: The "user" object structure appears ~122 times with identical fields. |
| 97 | + |
| 98 | +**Complexity:** Medium-High - requires structural hashing and reference resolution |
| 99 | + |
| 100 | +--- |
| 101 | + |
| 102 | +## Recommended Implementation Order |
| 103 | + |
| 104 | +| Phase | Approach | Savings | Cumulative Size | Complexity | |
| 105 | +|-------|----------|---------|-----------------|------------| |
| 106 | +| 1 | Short property names | 80 KB | 384 KB | Low | |
| 107 | +| 2 | Array-based structure | 79 KB | 305 KB | Medium | |
| 108 | +| 3 | String interning | 40 KB | 265 KB | High | |
| 109 | +| 4 | Subtree deduplication | 30-50 KB | 220-235 KB | High | |
| 110 | + |
| 111 | +**Phase 1 alone gets you 17% reduction with minimal code changes.** |
| 112 | + |
| 113 | +**Phases 1+2 combined get you ~34% reduction (464 KB → 305 KB).** |
| 114 | + |
| 115 | +--- |
| 116 | + |
| 117 | +## Implementation Notes |
| 118 | + |
| 119 | +### Phase 1: Short Property Names |
| 120 | + |
| 121 | +Update `minify-json.js` or create a transform in `update-webhooks` script: |
| 122 | + |
| 123 | +```javascript |
| 124 | +function shortenKeys(obj) { |
| 125 | + return { |
| 126 | + n: obj.name, |
| 127 | + d: obj.description, |
| 128 | + c: obj.childParamsGroups?.map(shortenKeys), |
| 129 | + b: obj.bodyParameters, |
| 130 | + a: obj.action |
| 131 | + }; |
| 132 | +} |
| 133 | +``` |
| 134 | + |
| 135 | +Update consumers to use short keys when reading `.min.json` files. |
| 136 | + |
| 137 | +### Phase 2: Array Format |
| 138 | + |
| 139 | +```javascript |
| 140 | +// [name, description, children] - omit trailing nulls |
| 141 | +function toArray(obj) { |
| 142 | + const children = obj.childParamsGroups?.map(toArray); |
| 143 | + if (children) return [obj.name, obj.description || null, children]; |
| 144 | + if (obj.description) return [obj.name, obj.description]; |
| 145 | + return [obj.name]; |
| 146 | +} |
| 147 | +``` |
0 commit comments