Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Improve DOMTokenList performance #3

Closed
wants to merge 9 commits into from
Closed

Improve DOMTokenList performance #3

wants to merge 9 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Jun 15, 2017

I was hoping to borrow some classes here and there — while I was there I thought why not.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling e996935 on flagello:performance/DOMTokenList into 6e74322 on WebReflection:master.

Copy link
Owner

@WebReflection WebReflection left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I really appreciate the fact you are that interested in this project, even if I told you it wasn't the right time to talk about performance yet ... but this PR went too far, example:

screenshot from 2017-06-15 20-29-35

I'm sorry, I'm against code pollution for no reason, and replacing a native array join in 2017 is no reason to me, same goes for includes, which also guards against other things too.

Just to re-clarify again, this project aim is not to be the fastest, I actually don't care at all now, it gave me the ability to facade the whole DOM in NativeScript and work as expected.

Here the key: working, and easy to maintain, to me are way more valuable things than for loops instead of native functionalities and I also believe micro benchmarks are the death of the platform.

Apologies if this comment does not welcome your interests about this projects, but either you drop all native replacements or I'm afraid I won't put myself in the situation to maintain unnecessary extra LOC for some millisecond I don't even believe is needed, at this stage (or ever, really, go compiled modules if performances has to be that extreme)

Hope you'll understand this comment.

Best Regards

this.push(token);
} else {
main: for (let i = 0; i < adding; i++) {
for (let j = 0; j < current; j++) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O(n^2) ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot see anything in that link but O(n^2) wasn't a question, rather a statement. The algorithm used in here is not even a performance oriented one so I'm afraid this change won't land in this project

if (i < 0) this.add(newToken);
else this[i] = newToken;
afterChanges(this);
for (let i = 0, n = this.length; i < n; i++) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you avoiding indexOf here? If that's the case ... why?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot see anything in that link but regardless indexOf is one word to maintain VS few lines so this change won't land in this project

return afterChanges(this);
}
}
this.add(newToken);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or maybe afterChanges was triggered twice? curious to know more about this one

@@ -23,7 +23,10 @@ module.exports = class DOMTokenList extends Array {
}

contains(token) {
return this.includes(token);
for (let i = 0, n = this.length; i < n; i++) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here you are avoiding native includes ... I'm not too fund of augmenting complexity for no reason when the platform provides default alternatives

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot see anything in that link but regardless includes does more than your code so this change won't land in this project

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a glaring oversight. I'll be sure to refer to the reference implementation. Thanks for pointing it out!

@ghost
Copy link
Author

ghost commented Jun 15, 2017

I understand entirely @WebReflection. I see your point and I welcome your approach, despite not fully agreeing with it.

(I'll leave reference replies to the relative comments, but they are by no means a way to dispute your ideas or work. Despite the striking difference: a) I'm not entirely sure how they translate in real-world usage; b) I didn't test them in Node. A contrasting observation might be that the difference could be more significant on mobile.)

@ghost ghost closed this Jun 15, 2017
@WebReflection
Copy link
Owner

WebReflection commented Jun 15, 2017

A contrasting observation might be that the difference could be more significant on mobile.

I've been around for too long to smell 10 years ago useless optimizations in here ... the JIT era went way beyond this and modern engines should be able to optimize better than JS itself.

I'm really not coding thinking that I cannot array.join(...) and nobody, not even new contributors, should ever feel intimidated by unnecessary bloat for benchmarks that are irrelevant not only in nodejs, but in this whole project scope.

Again, I appreciate your interest to this project but if it's crazy-faster-super-performance you are looking for, you're better off with any of the alternative out there, really: this project is not about crazy-fast performance ... this project is about bringing, with ease to read and contribute, a basic HTML env to any non HTML environment.

On nodeJS I would not use this, unless I've pre-created documents per page ... and there indeed the serialization via document.toString() is already the fastest and the only one I care but not at the point I cannot read anymore a bloody array.join() 😉

@WebReflection
Copy link
Owner

P.S. you can fork this project and bring in all the micro-benchmarks you want. Maybe one day all will be merged back together 😃

This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants