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

Delete never-used ks macros #1274

Closed
peterbe opened this issue Sep 17, 2020 · 6 comments · Fixed by #6249
Closed

Delete never-used ks macros #1274

peterbe opened this issue Sep 17, 2020 · 6 comments · Fixed by #6249
Labels
🧑‍🤝‍🧑 community contributions by our wonderful community 🐌 idle Issues and PRs without recent activity. Flagged for maintainer follow-up. macros tracking issues related to kumascript macros 🚉 platform keeping the platform healthy

Comments

@peterbe
Copy link
Contributor

peterbe commented Sep 17, 2020

Using the BUILD_LOG_MACROS_USED env var you can get a log of all ks macro calls. You can combine that log output with the listing of kumascript/macros/*.ejs to get the difference of what never appears in the log files. I.e. macros that are not used by any active content.

Here's a nifty Python script you can use:

import sys
from pathlib import Path
from collections import defaultdict

macros_used = defaultdict(int)

with open(sys.argv[1]) as f:
    for line in f:
        macro_name = line.split('|')[0]
        macros_used[macro_name] += 1

macros_possible = {
    x.name.lower().rsplit('.', 1)[0]:x for x in
    Path('kumascript/macros').iterdir()
    if x.name.endswith('.ejs')
}

flat = sorted([
    (macros_used.get(x) or -1, x) for x in macros_possible
], reverse=True)
# from pprint import pprint
# pprint(macros_used)
# from pprint import pprint
# pprint(macros_possible)

print("MOST POPULAR...")
for used, name in flat:
    if used > 0:
        print(f'{name:<30} {used:,}')
print('\n')


deletable = len([x for x,y in flat if x <=0])
print(f"DELETE WORTHY (never used) ({deletable})")
for used, name in flat:
    if used <= 0:
        print(macros_possible[name])

Equipped with this, we should be able to delete about 50 .ejs macros that are never used.

@peterbe
Copy link
Contributor Author

peterbe commented Sep 29, 2020

I think my python script is fine. Here's how you use it.

yarn prepare-build
export BUILD_MACROS_USED_LOGFILE=/tmp/macros-used.log
yarn build

...wait ~10min...

python peterbe__analyze_macros_used.py /tmp/macros-used.log

@peterbe
Copy link
Contributor Author

peterbe commented Feb 25, 2021

Today, now that Uplift is complete. I ran a complete build with BUILD_MACROS_USED_LOGFILE and analyzed which, compared to the kumascript/macros/*.ejs that were never executed.

kumascript/macros/jsapixref.ejs
kumascript/macros/jsapi_minversion_inline.ejs
kumascript/macros/jsapi_minversion_header.ejs
kumascript/macros/jsapi-requires-request.ejs

#3059

kumascript/macros/LocalizationStatusInSection.ejs
kumascript/macros/LegacyAddonsNotice.ejs
kumascript/macros/jsctypesSidebar.ejs

#3060

kumascript/macros/SpiderMonkeySidebar.ejs
kumascript/macros/SimpleBanner.ejs
kumascript/macros/SimpleBadge.ejs
kumascript/macros/Preferences_System_TOC.ejs

#3061

kumascript/macros/xref2.ejs
kumascript/macros/xref.ejs

#3062

@Ryuno-Ki
Copy link

Wow, that's a lot of cruft!
Another benefit of moving to GitHub, I guess?
(As in: this kind of analysis wouldn't have been possible with the wiki setup)

@peterbe
Copy link
Contributor Author

peterbe commented Feb 25, 2021

Note-to-self; The following are used in less than 10 places:

userlink                       9
cssanimatedproperties          9
訳語                             6
addonsidebarmain               3
tree                           2
lxrsearch                      2
b2gonlyheader2                 1

Might be worth hunting those down.

@peterbe
Copy link
Contributor Author

peterbe commented Feb 25, 2021

To worry about macros that are only ever used in translated content, let's discuss that in: #3063

@Ryuno-Ki
Copy link

What's the third one meant to mean? It shows [][] on my system (likely missing a font with those glyphs).
If I copy-paste them into a search engine, I get results like https://ja.wikipedia.org/wiki/%E8%A8%B3%E8%AA%9E - so something Japanese.

escattone pushed a commit that referenced this issue Feb 26, 2021
escattone pushed a commit that referenced this issue Feb 26, 2021
peterbe added a commit to peterbe/yari that referenced this issue Jun 1, 2021
peterbe added a commit to peterbe/yari that referenced this issue Jun 1, 2021
peterbe added a commit to peterbe/yari that referenced this issue Jun 1, 2021
peterbe added a commit to peterbe/yari that referenced this issue Jun 1, 2021
@schalkneethling schalkneethling added macros tracking issues related to kumascript macros 🚉 platform keeping the platform healthy labels Nov 3, 2021
@github-actions github-actions bot added the 🐌 idle Issues and PRs without recent activity. Flagged for maintainer follow-up. label Dec 10, 2021
@schalkneethling schalkneethling added the 🧑‍🤝‍🧑 community contributions by our wonderful community label Apr 15, 2022
caugner pushed a commit that referenced this issue May 12, 2022
Repository owner moved this from Backlog to Done in Yari Platform Engineering May 12, 2022
OnkarRuikar pushed a commit to OnkarRuikar/yari that referenced this issue Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧑‍🤝‍🧑 community contributions by our wonderful community 🐌 idle Issues and PRs without recent activity. Flagged for maintainer follow-up. macros tracking issues related to kumascript macros 🚉 platform keeping the platform healthy
Projects
Development

Successfully merging a pull request may close this issue.

4 participants