Skip to contentSkip to conversation

support/scripts/pkg-stats: move to procedurally generated row/column clases

PATCH Sen Hastings 1 participant 3 messages Aug 8, 2022 – Aug 30, 2022

lore
Share & tools
lore
#0 lore raw
Quoted 9 lines · Thomas Petazzoni

Hello,

Quoted 4 lines · On Fri, 5 Aug 2022 15:01:13 -0500 Sen Hastings <[email protected]> wrote:

Rather than having pre-baked classes in the markup for sorting purposes, all the cells in package-grid are iterated over at load time and given a row/column class.

Quoted 7 lines
Quoted 3 lines

example: https://sen-h.github.io/pkg-stats/b6f4cbddb14233c3ab3fdfea1e486c14871cfb2a.html

I am probably not versed enough into HTML/CSS/JS sorcery, but I don't understand the benefit of this. Could you explain a bit more?

Sure.

It turns out it's a lot cheaper (smaller) to have the client just iterate over every single cell and give it a row/column class selector instead of shipping it out with them.

sortGrid() sorts by virtue of all the elements in a column sharing the same class (which originally was also the column label)
and all the elements in a row also sharing the same class (which originally was also the package name).

The problem (previously) was that some package names were duplicated across rows.

For instance look at these two cells in the package column:

<div id="package_barebox" class="package data barebox">boot/barebox/barebox.mk</div>

<div id="package_barebox" class="package data barebox">boot/barebox/barebox/barebox.mk</div>

these are the beginning cells of two rows and they both share the *same* class selector "barebox".

Can't have that because we need every row to have a unique class assigned to it.

Otherwise when we sort this happens:

|label         |     label    |     label    |...|     label    |
|class1        |    class1    |    class1    |...|class1        |
|class1        |    class1    |    class1    |...|class1        |

becomes:

|label         |     label    |     label    |...|     label    |
|class1        |    class1    |    class1    |...|class1        |class1        |    class1    |    class1    |...|class1        |

sortGrid pulls all elements by row class selector and gives them an explicit grid-row assignment

So now we have 26 elements in a row instead of 13 :p

The fix at the time,

(see: https://git.buildroot.net/buildroot/commit/?id=786f8b45672ebdd432f6af5b7595d3d16013433b)

was to use the package path but with "_" instead of "/", so:
boot_barebox_barebox and boot_barebox_barebox_barebox respectively.

Also class selectors can't start with numbers so we prepend an "_" to for the sake of packages like 4th and 18xx-ti-utils.

The problem I noticed was that having

id="column_name__some_really_really_long_path_name" class="centered data _some_really_really_long_path_name"

for every element added up after 70k+ elements.

the old pkg-stats
(https://git.buildroot.net/buildroot/commit/?id=eae86599ca81c943821bac33f424669520a3fa8c)

when given the current package list gives me an html file sitting at
about 2.9MB.
example: https://sen-h.github.io/pkg-stats/eae86599ca81c943821bac33f424669520a3fa8c.html

The current pkg-stats gives me a whopping 7MB file.
example: https://sen-h.github.io/pkg-stats/c245575.html

but you can see this whittled down by [PATCH v2 1/2]:
https://sen-h.github.io/pkg-stats/b6f4cbddb14233c3ab3fdfea1e486c14871cfb2a.html
(3.2M)

and then by [PATCH v1 2/2]:
https://sen-h.github.io/pkg-stats/9ad05210dcd9e4fb6b6a45be87c0fbb3e022085b.html
(2.6M)

in essence, we go from:

<div id="upstream_url__package_kodi-audiodecoder-vgmstream_kodi-audiodecoder-vgmstream" class="centered upstream_url data _package_kodi-audiodecoder-vgmstream_kodi-audiodecoder-vgmstream good_url"><a href="https://github.com/xbmc/audiodecoder.vgmstream">Link</a></div>

and then with [PATCH v2 1/2]:

<div class="centered data good_url"><a href="https://github.com/xbmc/audiodecoder.vgmstream">Link</a></div>

which after our column/row class assignment script runs becomes:

<div class="centered data good_url c10 ir755"><a href="https://github.com/xbmc/audiodecoder.vgmstream">Link</a></div>

and finally with [PATCH v2 2/2]:

        <div class="good_url"><a href="https://github.com/xbmc/audiodecoder.vgmstream">Link</a></div>

and once again after the script runs:

        <div class="good_url c10 ir755"><a href="https://github.com/xbmc/audiodecoder.vgmstream">Link</a></div>

and here's the old sorttable version just for comparison:

<td class="centered missing_url invalid_url"><a href="https://github.com/xbmc/audiodecoder.vgmstream">invalid (err)</a></td>

So why not just ship the class selectors "cX irX" for every element instead of generating them client side?

I experimented with that but once again it's a size thing.

Every order of magnitude (10-100-1000) adds another digit (character) to the ir (initial row) class selector.

Right now it's about 300k which doesn't seem like much but could really add up over time.

The pages being generated right now would be considered *quite* big by most standards, so I'm really just trying to whittle everything down to the absolute bare minimum.

Quoted 12 lines

Review function sortGrid(sortLabel){ · line 788

Quoted 9 lines

function sortGrid(sortLabel){

(quoted diff) +1 -1
 	let i = 0;
 	let pkgSortArray = [], sortedPkgArray = [], pkgStringSortArray = [], pkgNumSortArray = [];
@@ -774,14 +785,11 @@ function sortGrid(sortLabel){
 	const styleSheet = styleElement.sheet;
 
         columnValues.shift();
-        columnValues.forEach((listing) => {
+	columnValues.forEach((listing) => {

This is a spurious change.

Quoted 6 lines

Review function sortGrid(sortLabel){ · line 790

Quoted 3 lines
(quoted diff) +1 -1
         if (fieldText == "see all " + fieldTotal + triangleDown){
-		field.firstElementChild.innerText = "see less " + fieldTotal + triangleUp;
+                field.firstElementChild.innerText = "see less " + fieldTotal + triangleUp;

This is also a spurious change.

Shoot, those are pretty spurious. I'll go ahead and fix that.

Quoted 3 lines

Thanks!

Thomas

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#1 lore raw

Re: [Buildroot] [PATCH v1 2/2] support/scripts/pkg-stats: optimize CSS selector usage

Quoted 5 lines · Thomas Petazzoni

Hello Sen,

On Fri, 5 Aug 2022 15:01:14 -0500
Sen Hastings <[email protected]> wrote:

Quoted 7 lines
Quoted 5 lines

Having lots of CSS selector declarations adds up, especially at 70k+ elements.

This reduces the number of CSS selectors printed in the markup to the bare minimum, by using pseudo-classes and tag names as selectors.

Not sure how this works.

See my explination below about magic number 13. :-)

Quoted 1 line

Is there a significant size benefit?

Absolutely. I actually had a cover letter for v0 of the patchset:
https://lore.kernel.org/buildroot/[email protected]/

Just as a quick rundown:

The old pkg-stats,
(https://git.buildroot.net/buildroot/commit/?id=eae86599ca81c943821bac33f424669520a3fa8c)

when given the current package list gives me an html file sitting at about 2.9MB.
example: https://sen-h.github.io/pkg-stats/eae86599ca81c943821bac33f424669520a3fa8c.html

The current pkg-stats gives me a whopping 7MB file.
example: https://sen-h.github.io/pkg-stats/c245575.html

but you can see this whittled down by [PATCH v2 1/2]:
https://sen-h.github.io/pkg-stats/b6f4cbddb14233c3ab3fdfea1e486c14871cfb2a.html
(3.2M)

and then by [PATCH v1 2/2]:
https://sen-h.github.io/pkg-stats/9ad05210dcd9e4fb6b6a45be87c0fbb3e022085b.html
(2.6M)

Quoted 2 lines

Sometimes having a dumb but obvious solution is better than having a smart but convoluted solution.

Although I admit nth-child seems exotic, I think it's actually pretty straightforward. CSS is of course all about cascade and layers of specificity,
and I definitely think the size savings is worth it.

Quoted 15 lines

Review

Quoted 13 lines
(quoted diff) +12 -0
+div {
+  text-align: center;
+  border: solid 1px gray;
+}
+#results-grid div{
+  text-align: left;
+}
+#package-grid div:nth-child(13n+1), #package-grid div:nth-child(13n+13)  {
+  text-align: left;
+}
+#package-grid div:nth-child(13){
+  text-align: center;

What is this 13 magic number?

13 is the the number of columns.

Rather than giving every item that needs to be centered a "centered" class selector, we center all div elements and then selectively left-align the ones we want.

div { text-align: center;}:

centers all div elements, which includes the cells in the grid.

	#package-grid div:nth-child(13n+1):

selects the first element in the grid and then every 13th+1 element thereafter:

(13*0)+1 = 1, (13*1)+1 = 14, (13*2)+1 = 27 etc...

this effectively targets every cell in the left-most column.

	#package-grid div:nth-child(13n+13):

selects the 13th element in the grid and then every 13th element thereafter:

(13*0)+13 = 13, (13*1)+13 = 26, (13*2)+13 = 39 etc...

this effectively targets every cell in the right-most column.

so our columns go from this:

      1		   2		3	4-12	 13
|   label    |   label    |   label    |...|   label    |
|    data    |    data    |    data    |...|    data    |

to this:

      1		   2		3	4-12	 13
|label       |   label    |   label    |...|label       |
|data        |    data    |    data    |...|data        |

Except that traditionally the right-most column label is centered. (at least that's how it was when I started)

so we use:

	#package-grid div:nth-child(13){text-align: center;}

to center *just* the right-most column label (the 13th element)

so now it's:

      1		   2		3	4-12	 13
|label       |   label    |   label    |...|   label    |
|data        |    data    |    data    |...|data        |

see: https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child#examples

Quoted 9 lines

Also, unrelated to this, when I look at the currently generated HTML, it looks odd. I see things like this:

<div id="upstream_url__package_kodi-audiodecoder-vgmstream_kodi-audiodecoder-vgmstream" class="centered upstream_url data _package_kodi-audiodecoder-vgmstream_kodi-audiodecoder-vgmstream good_url"><a href="https://github.com/xbmc/audiodecoder.vgmstream">Link</a></div>

Why do we have these crazy id values now? why does the class property contain a value such as _package_kodi-audiodecoder-vgmstream_kodi-audiodecoder-vgmstream?

Good question. It has to do with sortGrid() needing unique class selectors per row.

see: https://git.buildroot.net/buildroot/commit/?id=786f8b45672ebdd432f6af5b7595d3d16013433b

sortGrid() sorts by virtue of all the elements in a column sharing the same class (which orginally was also the column label)
and all the elements in a row also sharing the same class (which originally was also the package name).

The problem (previously) was that some package names were duplicated across rows.

For instance look at these two cells in the package column:

<div id="package_barebox" class="package data barebox">boot/barebox/barebox.mk</div>

<div id="package_barebox" class="package data barebox">boot/barebox/barebox/barebox.mk</div>

these are the beginning cells of two rows and they both share the *same* class selector "barebox".

Can't have that because we need every row to have a unique class assigned to it.

Otherwise when we sort this happens:

|label         |     label    |     label    |...|     label    |
|class1        |    class1    |    class1    |...|class1        |
|class1        |    class1    |    class1    |...|class1        |

becomes:

|label         |     label    |     label    |...|     label    |
|class1        |    class1    |    class1    |...|class1        |class1        |    class1    |    class1    |...|class1        |

sortGrid pulls all elements by row class selector and gives them an explicit grid-row assignment.

So now we have 26 elements in a row instead of 13 :p

The fix at the time,was to use the package path but with "_" instead of "/", so:

boot_barebox_barebox and boot_barebox_barebox_barebox respectively.

Also class selectors can't start with numbers so we prepend an "_" to for the sake of packages like 4th and 18xx-ti-utils.

sortGrid (used to) derive the package class selector for the whole row by stripping it out of the id.

	sortArr[0] = listing.id.replace(sortLabel+"_", "");

so:
sortArr[0] = "upstream_url__package_kodi-audiodecoder-vgmstream_kodi-audiodecoder-vgmstream".replace("upstream_url_", "")
yielding:
sortArr[0] = "_package_kodi-audiodecoder-vgmstream_kodi-audiodecoder-vgmstream"

PATCH v2 1/2 does away with this and uses programmatically generated column/row class selectors.

I understand that javascript probably isn't a langauge most people on the mailing list are familiar with, especially when it comes to the DOM api.

So this email (and the previous one) are more of "why" and less of a "how", but if it would be helpful I could do a line-by-line walkthrough of sortGrid() just to go through how everything works.

Hope that helps.

Quoted 3 lines

Thanks!

Thomas

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#2 lore raw

Re: [Buildroot] [PATCH v1 2/2] support/scripts/pkg-stats: optimize CSS selector usage

Quoted 5 lines · Thomas Petazzoni

Hello Sen,

On Fri, 5 Aug 2022 15:01:14 -0500
Sen Hastings <[email protected]> wrote:

Quoted 7 lines
Quoted 5 lines

Having lots of CSS selector declarations adds up, especially at 70k+ elements.

This reduces the number of CSS selectors printed in the markup to the bare minimum, by using pseudo-classes and tag names as selectors.

Not sure how this works.

See my explination below about magic number 13. :-)

Quoted 1 line

Is there a significant size benefit?

Absolutely. I actually had a cover letter for v0 of the patchset:
https://lore.kernel.org/buildroot/[email protected]/

Just as a quick rundown:

The old pkg-stats,
(https://git.buildroot.net/buildroot/commit/?id=eae86599ca81c943821bac33f424669520a3fa8c)

when given the current package list gives me an html file sitting at about 2.9MB.
example: https://sen-h.github.io/pkg-stats/eae86599ca81c943821bac33f424669520a3fa8c.html

The current pkg-stats gives me a whopping 7MB file.
example: https://sen-h.github.io/pkg-stats/c245575.html

but you can see this whittled down by [PATCH v2 1/2]:
https://sen-h.github.io/pkg-stats/b6f4cbddb14233c3ab3fdfea1e486c14871cfb2a.html
(3.2M)

and then by [PATCH v1 2/2]:
https://sen-h.github.io/pkg-stats/9ad05210dcd9e4fb6b6a45be87c0fbb3e022085b.html
(2.6M)

Quoted 2 lines

Sometimes having a dumb but obvious solution is better than having a smart but convoluted solution.

Although I admit nth-child seems exotic, I think it's actually pretty straightforward. CSS is of course all about cascade and layers of specificity,
and I definitely think the size savings is worth it.

Quoted 15 lines

Review

Quoted 13 lines
(quoted diff) +12 -0
+div {
+  text-align: center;
+  border: solid 1px gray;
+}
+#results-grid div{
+  text-align: left;
+}
+#package-grid div:nth-child(13n+1), #package-grid div:nth-child(13n+13)  {
+  text-align: left;
+}
+#package-grid div:nth-child(13){
+  text-align: center;

What is this 13 magic number?

13 is the the number of columns.

Rather than giving every item that needs to be centered a "centered" class selector, we center all div elements and then selectively left-align the ones we want.

div { text-align: center;}:

centers all div elements, which includes the cells in the grid.

	#package-grid div:nth-child(13n+1):

selects the first element in the grid and then every 13th+1 element thereafter:

(13*0)+1 = 1, (13*1)+1 = 14, (13*2)+1 = 27 etc...

this effectively targets every cell in the left-most column.

	#package-grid div:nth-child(13n+13):

selects the 13th element in the grid and then every 13th element thereafter:

(13*0)+13 = 13, (13*1)+13 = 26, (13*2)+13 = 39 etc...

this effectively targets every cell in the right-most column.

so our columns go from this:

      1		   2		3	4-12	 13
|   label    |   label    |   label    |...|   label    |
|    data    |    data    |    data    |...|    data    |

to this:

      1		   2		3	4-12	 13
|label       |   label    |   label    |...|label       |
|data        |    data    |    data    |...|data        |

Except that traditionally the right-most column label is centered. (at least that's how it was when I started)

so we use:

	#package-grid div:nth-child(13){text-align: center;}

to center *just* the right-most column label (the 13th element)

so now it's:

      1		   2		3	4-12	 13
|label       |   label    |   label    |...|   label    |
|data        |    data    |    data    |...|data        |

see: https://developer.mozilla.org/en-US/docs/Web/CSS/:nth-child#examples

Quoted 9 lines

Also, unrelated to this, when I look at the currently generated HTML, it looks odd. I see things like this:

<div id="upstream_url__package_kodi-audiodecoder-vgmstream_kodi-audiodecoder-vgmstream" class="centered upstream_url data _package_kodi-audiodecoder-vgmstream_kodi-audiodecoder-vgmstream good_url"><a href="https://github.com/xbmc/audiodecoder.vgmstream">Link</a></div>

Why do we have these crazy id values now? why does the class property contain a value such as _package_kodi-audiodecoder-vgmstream_kodi-audiodecoder-vgmstream?

Good question. It has to do with sortGrid() needing unique class selectors per row.

see: https://git.buildroot.net/buildroot/commit/?id=786f8b45672ebdd432f6af5b7595d3d16013433b

sortGrid() sorts by virtue of all the elements in a column sharing the same class (which orginally was also the column label)
and all the elements in a row also sharing the same class (which originally was also the package name).

The problem (previously) was that some package names were duplicated across rows.

For instance look at these two cells in the package column:

<div id="package_barebox" class="package data barebox">boot/barebox/barebox.mk</div>

<div id="package_barebox" class="package data barebox">boot/barebox/barebox/barebox.mk</div>

these are the beginning cells of two rows and they both share the *same* class selector "barebox".

Can't have that because we need every row to have a unique class assigned to it.

Otherwise when we sort this happens:

|label         |     label    |     label    |...|     label    |
|class1        |    class1    |    class1    |...|class1        |
|class1        |    class1    |    class1    |...|class1        |

becomes:

|label         |     label    |     label    |...|     label    |
|class1        |    class1    |    class1    |...|class1        |class1        |    class1    |    class1    |...|class1        |

sortGrid pulls all elements by row class selector and gives them an explicit grid-row assignment.

So now we have 26 elements in a row instead of 13 :p

The fix at the time,was to use the package path but with "_" instead of "/", so:

boot_barebox_barebox and boot_barebox_barebox_barebox respectively.

Also class selectors can't start with numbers so we prepend an "_" to for the sake of packages like 4th and 18xx-ti-utils.

sortGrid (used to) derive the package class selector for the whole row by stripping it out of the id.

	sortArr[0] = listing.id.replace(sortLabel+"_", "");

so:
sortArr[0] = "upstream_url__package_kodi-audiodecoder-vgmstream_kodi-audiodecoder-vgmstream".replace("upstream_url_", "")
yielding:
sortArr[0] = "_package_kodi-audiodecoder-vgmstream_kodi-audiodecoder-vgmstream"

PATCH v2 1/2 does away with this and uses programmatically generated column/row class selectors.

I understand that javascript probably isn't a langauge most people on the mailing list are familiar with, especially when it comes to the DOM api.

So this email (and the previous one) are more of "why" and less of a "how", but if it would be helpful I could do a line-by-line walkthrough of sortGrid() just to go through how everything works.

Hope that helps.

[note: I originally sent this out on the 2022-08-08, but not as reply to the previous message,
so it just showed up as a normal submission to the mailing list. Re-submitting it for the sake of posterity.]

Quoted 3 lines

Thanks!

Thomas

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot