-
Notifications
You must be signed in to change notification settings - Fork 2
361 lines (326 loc) · 18.9 KB
/
prioritize-unused-includes.yml
File metadata and controls
361 lines (326 loc) · 18.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
name: Prioritize Unused Chromium Includes
on:
workflow_dispatch:
schedule:
- cron: '0 18 * * *'
permissions: {}
jobs:
prioritized_by_added_size:
name: Prioritized by added size
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: dsanders11/chromium-include-cleanup
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: '3.12'
cache: 'pip'
- name: Install Dependencies
run: pip install -r requirements.txt
- name: Download Unused Includes Output
run: |
curl https://gist.githubusercontent.com/dsanders11/ccf3505dcbb35492cbadade1ceb663b6/raw/unused-includes.csv > unused-includes.csv
- name: Download Include Analysis Output
run: |
curl https://commondatastorage.googleapis.com/chromium-browser-clang/include-analysis.js > include-analysis.js
- name: Find Priority Unused Includes
run: |
python set_edge_weights.py unused-includes.csv include-analysis.js --config chromium > weighted-unused-includes.csv
python filter_include_changes.py weighted-unused-includes.csv --config chromium --filter-third-party --no-filter-mojom-headers --weight-threshold 10000000 > priority-unused-includes.csv
python set_edge_weights.py priority-unused-includes.csv include-analysis.js --config chromium --metric expanded_size > priority-unused-includes.expanded_size.csv
python set_edge_weights.py priority-unused-includes.csv include-analysis.js --config chromium --metric prevalence > priority-unused-includes.prevalence.csv
python set_edge_weights.py priority-unused-includes.csv include-analysis.js --config chromium --metric includer_size > priority-unused-includes.includer_size.csv
python set_edge_weights.py priority-unused-includes.csv include-analysis.js --config chromium --metric centrality > priority-unused-includes.centrality.csv
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: weighted-unused-includes
path: |
weighted-unused-includes.csv
priority-unused-includes.csv
priority-unused-includes.expanded_size.csv
priority-unused-includes.prevalence.csv
priority-unused-includes.includer_size.csv
priority-unused-includes.centrality.csv
- run: npm install @actions/cache
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const fs = require('node:fs');
const cache = await import('${{ github.workspace }}/node_modules/@actions/cache/lib/cache.js');
const data = fs.readFileSync('./priority-unused-includes.csv', 'utf8').trim().split('\n');
const expandedSizeData = fs.readFileSync('./priority-unused-includes.expanded_size.csv', 'utf8').trim().split('\n');
const prevalenceData = fs.readFileSync('./priority-unused-includes.prevalence.csv', 'utf8').trim().split('\n');
const includerSizeData = fs.readFileSync('./priority-unused-includes.includer_size.csv', 'utf8').trim().split('\n');
const centralityData = fs.readFileSync('./priority-unused-includes.centrality.csv', 'utf8').trim().split('\n');
let totalAddedSize = 0;
const unusedIncludes = await Promise.all(data.map(async (line, idx) => {
const [,, filename, include, added_size] = line.trim().split(',');
const addedSize = parseInt(added_size);
totalAddedSize += addedSize;
// Check if this is known from a previous run
const cacheKey = `prioritize-unused-chromium-${filename}-${include}`;
const cacheHit =
(await cache.restoreCache(['/dev/null'], cacheKey, undefined, {
lookupOnly: true,
})) !== undefined;
if (!cacheHit) {
// Create a cache entry (only the name matters) to keep track of
// includes we've seen from previous runs to mark them as stale
await cache.saveCache(['/dev/null'], cacheKey);
}
return [
`${filename} --> ${include.replace(/</g, '<').replace(/>/g, '>')}`,
addedSize,
parseFloat(prevalenceData[idx].trim().split(',')[4]),
parseInt(expandedSizeData[idx].trim().split(',')[4]),
parseInt(includerSizeData[idx].trim().split(',')[4]),
parseFloat(centralityData[idx].trim().split(',')[4]),
cacheHit,
];
}));
const addTable = (includes) => {
core.summary.addTable([
[
{ data: 'Include Edge', header: true },
{ data: 'Added Size', header: true },
{ data: 'Prevalence', header: true },
{ data: 'Expanded Size', header: true },
{ data: 'Includer Size', header: true },
{ data: 'Centrality', header: true },
],
// Sort by added size, then convert it back to string or it won't render
...includes
.sort((a, b) => b[1] - a[1])
.map(([edge, added_size, prevalence, expandedSize, includerSize, centrality]) => [
edge,
added_size.toLocaleString(),
`${prevalence.toFixed(2)}%`,
expandedSize.toLocaleString(),
includerSize.toLocaleString(),
centrality.toFixed(5),
]),
]);
}
if (unusedIncludes.length > 0) {
core.summary.addHeading('✂️ Priority Unused Chromium Includes');
core.summary.addRaw(`\n> [!NOTE]\n> These are suggestions from \`clangd\` and are known to contain false positives.\n\n`);
core.summary.addRaw(`Found ${unusedIncludes.length} unused includes over 10 MB of added size for a total of ${totalAddedSize.toLocaleString()} bytes of added size`);
const newlySeen = unusedIncludes.filter(([, , , , , , cacheHit]) => !cacheHit)
if (newlySeen.length > 0) {
core.summary.addHeading('Not Seen Before', '2');
addTable(newlySeen);
core.summary.addHeading('All Unused Includes', '2');
} else {
core.summary.addBreak();
}
addTable(unusedIncludes);
} else {
core.summary.addRaw('🎉 No priority unused Chromium includes');
}
await core.summary.write();
prioritized_by_prevalence:
name: Prioritized by prevalence
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: dsanders11/chromium-include-cleanup
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: '3.12'
cache: 'pip'
- name: Install Dependencies
run: pip install -r requirements.txt
- name: Download Unused Includes Output
run: |
curl https://gist.githubusercontent.com/dsanders11/ccf3505dcbb35492cbadade1ceb663b6/raw/unused-includes.csv > unused-includes.csv
- name: Download Include Analysis Output
run: |
curl https://commondatastorage.googleapis.com/chromium-browser-clang/include-analysis.js > include-analysis.js
- name: Find Priority Unused Includes
run: |
python set_edge_weights.py unused-includes.csv include-analysis.js --config chromium --metric prevalence > weighted-unused-includes.csv
python filter_include_changes.py weighted-unused-includes.csv --config chromium --filter-third-party --no-filter-mojom-headers --weight-threshold 5 > priority-unused-includes.prevalence.csv
python set_edge_weights.py priority-unused-includes.prevalence.csv include-analysis.js --config chromium --metric expanded_size > priority-unused-includes.expanded_size.csv
python set_edge_weights.py priority-unused-includes.prevalence.csv include-analysis.js --config chromium --metric input_size > priority-unused-includes.input_size.csv
python set_edge_weights.py priority-unused-includes.prevalence.csv include-analysis.js --config chromium --metric includer_size > priority-unused-includes.includer_size.csv
python set_edge_weights.py priority-unused-includes.prevalence.csv include-analysis.js --config chromium --metric centrality > priority-unused-includes.centrality.csv
- run: npm install @actions/cache
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const fs = require('node:fs');
const cache = await import('${{ github.workspace }}/node_modules/@actions/cache/lib/cache.js');
const addedSizeData = fs.readFileSync('./priority-unused-includes.input_size.csv', 'utf8').trim().split('\n');
const expandedSizeData = fs.readFileSync('./priority-unused-includes.expanded_size.csv', 'utf8').trim().split('\n');
const prevalenceData = fs.readFileSync('./priority-unused-includes.prevalence.csv', 'utf8').trim().split('\n');
const includerSizeData = fs.readFileSync('./priority-unused-includes.includer_size.csv', 'utf8').trim().split('\n');
const centralityData = fs.readFileSync('./priority-unused-includes.centrality.csv', 'utf8').trim().split('\n');
const unusedIncludes = await Promise.all(prevalenceData.map(async (line, idx) => {
const [,, filename, include, prevalence] = line.trim().split(',');
// Check if this is known from a previous run
const cacheKey = `prioritize-unused-chromium-${filename}-${include}-prevalence`;
const cacheHit =
(await cache.restoreCache(['/dev/null'], cacheKey, undefined, {
lookupOnly: true,
})) !== undefined;
if (!cacheHit) {
// Create a cache entry (only the name matters) to keep track of
// includes we've seen from previous runs to mark them as stale
await cache.saveCache(['/dev/null'], cacheKey);
}
return [
`${filename} --> ${include.replace(/</g, '<').replace(/>/g, '>')}`,
parseFloat(prevalence),
parseInt(addedSizeData[idx].trim().split(',')[4]),
parseInt(expandedSizeData[idx].trim().split(',')[4]),
parseInt(includerSizeData[idx].trim().split(',')[4]),
parseFloat(centralityData[idx].trim().split(',')[4]),
cacheHit,
];
}));
const addTable = (includes) => {
core.summary.addTable([
[
{ data: 'Include Edge', header: true },
{ data: 'Prevalence', header: true },
{ data: 'Added Size', header: true },
{ data: 'Expanded Size', header: true },
{ data: 'Includer Size', header: true },
{ data: 'Centrality', header: true },
],
// Sort by prevalence, then convert it back to string or it won't render
...includes
.sort((a, b) => b[1] - a[1])
.map(([edge, prevalence, added_size, expandedSize, includerSize, centrality]) => [
edge,
`${prevalence.toFixed(2)}%`,
added_size.toLocaleString(),
expandedSize.toLocaleString(),
includerSize.toLocaleString(),
centrality.toFixed(5),
]),
]);
}
if (unusedIncludes.length > 0) {
core.summary.addHeading('✂️ Priority Unused Chromium Includes');
core.summary.addRaw(`\n> [!NOTE]\n> These are suggestions from \`clangd\` and are known to contain false positives.\n\n`);
core.summary.addRaw(`Found ${unusedIncludes.length} unused includes with over 5% prevalence`);
const newlySeen = unusedIncludes.filter(([, , , , , , cacheHit]) => !cacheHit)
if (newlySeen.length > 0) {
core.summary.addHeading('Not Seen Before', '2');
addTable(newlySeen);
core.summary.addHeading('All Unused Includes', '2');
} else {
core.summary.addBreak();
}
addTable(unusedIncludes);
} else {
core.summary.addRaw('🎉 No priority unused Chromium includes');
}
await core.summary.write();
prioritized_by_centrality:
name: Prioritized by centrality
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: dsanders11/chromium-include-cleanup
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: '3.12'
cache: 'pip'
- name: Install Dependencies
run: pip install -r requirements.txt
- name: Download Unused Includes Output
run: |
curl https://gist.githubusercontent.com/dsanders11/ccf3505dcbb35492cbadade1ceb663b6/raw/unused-includes.csv > unused-includes.csv
- name: Download Include Analysis Output
run: |
curl https://commondatastorage.googleapis.com/chromium-browser-clang/include-analysis.js > include-analysis.js
- name: Find Priority Unused Includes
run: |
python set_edge_weights.py unused-includes.csv include-analysis.js --config chromium --metric centrality > weighted-unused-includes.csv
python filter_include_changes.py weighted-unused-includes.csv --config chromium --filter-third-party --no-filter-mojom-headers --weight-threshold 0.005 > priority-unused-includes.centrality.csv
python set_edge_weights.py priority-unused-includes.centrality.csv include-analysis.js --config chromium --metric expanded_size > priority-unused-includes.expanded_size.csv
python set_edge_weights.py priority-unused-includes.centrality.csv include-analysis.js --config chromium --metric input_size > priority-unused-includes.input_size.csv
python set_edge_weights.py priority-unused-includes.centrality.csv include-analysis.js --config chromium --metric includer_size > priority-unused-includes.includer_size.csv
python set_edge_weights.py priority-unused-includes.centrality.csv include-analysis.js --config chromium --metric prevalence > priority-unused-includes.prevalence.csv
- run: npm install @actions/cache
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const fs = require('node:fs');
const cache = await import('${{ github.workspace }}/node_modules/@actions/cache/lib/cache.js');
const addedSizeData = fs.readFileSync('./priority-unused-includes.input_size.csv', 'utf8').trim().split('\n');
const expandedSizeData = fs.readFileSync('./priority-unused-includes.expanded_size.csv', 'utf8').trim().split('\n');
const prevalenceData = fs.readFileSync('./priority-unused-includes.prevalence.csv', 'utf8').trim().split('\n');
const includerSizeData = fs.readFileSync('./priority-unused-includes.includer_size.csv', 'utf8').trim().split('\n');
const centralityData = fs.readFileSync('./priority-unused-includes.centrality.csv', 'utf8').trim().split('\n');
const unusedIncludes = await Promise.all(centralityData.map(async (line, idx) => {
const [,, filename, include, centrality] = line.trim().split(',');
// Check if this is known from a previous run
const cacheKey = `prioritize-unused-chromium-${filename}-${include}-centrality`;
const cacheHit =
(await cache.restoreCache(['/dev/null'], cacheKey, undefined, {
lookupOnly: true,
})) !== undefined;
if (!cacheHit) {
// Create a cache entry (only the name matters) to keep track of
// includes we've seen from previous runs to mark them as stale
await cache.saveCache(['/dev/null'], cacheKey);
}
return [
`${filename} --> ${include.replace(/</g, '<').replace(/>/g, '>')}`,
parseFloat(centrality),
parseInt(addedSizeData[idx].trim().split(',')[4]),
parseFloat(prevalenceData[idx].trim().split(',')[4]),
parseInt(expandedSizeData[idx].trim().split(',')[4]),
parseInt(includerSizeData[idx].trim().split(',')[4]),
cacheHit,
];
}));
const addTable = (includes) => {
core.summary.addTable([
[
{ data: 'Include Edge', header: true },
{ data: 'Centrality', header: true },
{ data: 'Added Size', header: true },
{ data: 'Prevalence', header: true },
{ data: 'Expanded Size', header: true },
{ data: 'Includer Size', header: true },
],
// Sort by centrality
...includes
.sort((a, b) => b[1] - a[1])
.map(([edge, centrality, added_size, prevalence, expandedSize, includerSize]) => [
edge,
centrality.toFixed(5),
added_size.toLocaleString(),
`${prevalence.toFixed(2)}%`,
expandedSize.toLocaleString(),
includerSize.toLocaleString(),
]),
]);
}
if (unusedIncludes.length > 0) {
core.summary.addHeading('✂️ Priority Unused Chromium Includes');
core.summary.addRaw(`\n> [!NOTE]\n> These are suggestions from \`clangd\` and are known to contain false positives.\n\n`);
core.summary.addRaw(`Found ${unusedIncludes.length} unused includes with >= 0.005 centrality`);
const newlySeen = unusedIncludes.filter(([, , , , , , cacheHit]) => !cacheHit)
if (newlySeen.length > 0) {
core.summary.addHeading('Not Seen Before', '2');
addTable(newlySeen);
core.summary.addHeading('All Unused Includes', '2');
} else {
core.summary.addBreak();
}
addTable(unusedIncludes);
} else {
core.summary.addRaw('🎉 No priority unused Chromium includes');
}
await core.summary.write();