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

Robustness comparison #1

Open
dandv opened this issue Aug 24, 2015 · 7 comments
Open

Robustness comparison #1

dandv opened this issue Aug 24, 2015 · 7 comments
Labels

Comments

@dandv
Copy link
Contributor

dandv commented Aug 24, 2015

First off, fantastic work on my request to compare this library with alternatives! In 6+ years of being active on GitHub, this is the best I've seen, by far, hands-down.

Besides speed and selector length, a critical attribute of generated selectors is robustness to changes in the page structure. The open-source Hypothes.is project has written an extensive piece on that at https://hypothes.is/blog/fuzzy-anchoring/ and they have some OSS repos too.

@fczbkk
Copy link
Owner

fczbkk commented Aug 25, 2015

@dandv What exactly do you mean by robustness? How would you test it?

I read the article and it seems that what they do is out of scope of all tested libraries. They are targeting a specific snippet of text in the document. So they combine the CSS selector with a text selection range. How does this apply to libraries for generating just the CSS selectors?

@dandv
Copy link
Contributor Author

dandv commented Aug 26, 2015

By robustness I meant "robustness to changes in the page structure". Here's a blog post + solution that talks about that: http://www.timvasil.com/blog14/post/2014/02/24/Build-a-unique-selector-for-any-DOM-element-using-jQuery.aspx

For example, an nth-child() selector is less robust than an id-based selector. How to test and score this, is a good question.

@fczbkk
Copy link
Owner

fczbkk commented Aug 26, 2015

Ok, I understand now. I'll try to think of some way to test it.

I suspect that my library will be the winner in robustness, because it:

  • uses nth-child selector as a last resort
  • tries to find minimum viable selector, so it doesn't include all the parents in the child-selector chain

I guess that the only way to increase the "robustness index" of CSS generator would be to not use child-selector if possible. But I have tried that, but performance was an issue. I could not find a way to do it effectively.

@dandv
Copy link
Contributor Author

dandv commented Aug 26, 2015

What would be some use cases when performance is critical?

My use case is similar to linklink.io (create a deep link to an arbitrary paragraph) or gottafix.it. In both cases, only one selector is generated per page, and the bottleneck is user input.

@fczbkk
Copy link
Owner

fczbkk commented Aug 26, 2015

When you are really tring to optimize the CSS selectors, you have to check lots of various combinations for uniqueness. With every parent element of the target element, the complexity grows exponentialy. When I was doing tests on elements with 10 parents, it took around two seconds on my strong machine and the CPU usage went through the roof.

I think it could be done with some clever algorithm, that would filter out obviously wrong combinations before testing them. But I never really needed it, so I didn't even try to come up with something.

@dandv
Copy link
Contributor Author

dandv commented Aug 26, 2015

Worth adding an option then to control the optimization of selectors?

@fczbkk
Copy link
Owner

fczbkk commented Aug 26, 2015

I think it would be better to figure out a way to do it correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants