edbrowse-dev - development list for edbrowse
 help / color / mirror / Atom feed
From: Karl Dahlke <eklhad@comcast.net>
To: Edbrowse-dev@lists.the-brannons.com
Subject: [Edbrowse-dev] stackoverflow and css
Date: Sun, 11 Feb 2018 16:03:33 -0500	[thread overview]
Message-ID: <20180111160333.eklhad@comcast.net> (raw)
In-Reply-To: <20180211194301.gx6i6nago4ietkxo@toaster>

[-- Attachment #1: Type: text/plain, Size: 2244 bytes --]

Ok, querySelectorAll was built to run once and work, without regard to the fact that it might run thousands of times over.
Imagine a routine querySelectorAll_prep that traverses the document tree and does things like

hashnodes[e.nodeName].push(e);

So all the div nodes are in the array hashnodes["div"}.
If you have a div selector then just run down this array.
But more common is nodetype with class.

hashnodes[e.nodeName + "||" + e.className].push(e);

If the selector is div.class then you just scoot down a very short array.
Beyond this, there are no checks needed for an unadorned div.class, just apply the attributes.
Even if there are other checks, like div.class and foo=bar, at least you have a short array to check.
You might also set

hashnodes["||" + e.className].push(e);

That lets you look for .xyz i.e. any element of class xyz.
And you need to put every element in hashnodes["*"] because some selectors are just exotic and not tied to a particular node type or class.

But it's a little more complicated.
A selector could be

p.dog,div.cat

That's two selectors in one.
We would have to separate them, split(",");
and iterate over the two selectors, as though they had been separate from the get-go.
Not hard, just another wrinkle.

As I do today, getComputedStyle needs to run querySelectorAll on one particular node, not needing any of the above machinery.
That is the second argument to querySelectorAll as it stands today, a particular node to start at,
but it tries to do the subtree, so I remove the children first, then run querySelectorAll(selectors, e), then put the children back. It's gross.
See third.js line 3947.

Before you or I or anyone takes a whack at this, I'm going to list out all the selectors from stackoverflow,
to get an idea of what is there, and what kind of savings we might realize from the aforementioned node hashing.

Glad to see you back on the list, we miss your talent and your insights.
Maybe you could tackle one of these projects, if you have time,
gopher or querySelectorAll optimization or infinite loop debugging,
whichever one tickles your fancy.
Or anyone else who wants to step up.
I'll keep doing some light research.

Karl Dahlke

  reply	other threads:[~2018-02-11 21:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-11 18:53 Karl Dahlke
2018-02-11 19:25 ` Adam Thompson
2018-02-11 19:43   ` Adam Thompson
2018-02-11 21:03     ` Karl Dahlke [this message]
2018-02-11 21:24     ` Karl Dahlke
2018-02-13 19:05       ` Adam Thompson
2018-02-11 23:08     ` Karl Dahlke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180111160333.eklhad@comcast.net \
    --to=eklhad@comcast.net \
    --cc=Edbrowse-dev@lists.the-brannons.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).