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

Idea: Try to implement asm.js #108

Closed
pvdz opened this issue Jul 2, 2016 · 3 comments
Closed

Idea: Try to implement asm.js #108

pvdz opened this issue Jul 2, 2016 · 3 comments

Comments

@pvdz
Copy link
Contributor

pvdz commented Jul 2, 2016

The idea of asm.js is to use certain operations to force values to be of a certain type. The overhead this causes is eliminated by the browser which will know about these tricks and at the same time they work as type annotations which allow the browser to be more effective when optimizing. An example is let foo = getCount(); foo = foo|0; return foo;. The browser will eliminate the |0 line and assume the returned value is an integer.

I'm not entirely sure how precise these additions have to be and how complete. You tell the browser you use asm.js with the "use asm" header and it will kick you into this mode.

There's various articles on the web on asmjs, like here.

For finitedomain it could mean some improvements though I'm not certain how much. Additionally it would either mean we would need to translate the code to asmjs with a tool first. We don't want asmjs in our regular code base. I'm not sure how much effort is needed for that. But we should check it because if the effort is low, or can for the most part be done through jsdocs then we should totally do it. It'd basically be "free".

pvdz added a commit that referenced this issue Jul 11, 2016
=============================== Coverage summary ================
Statements   : 92.49% ( 3657/3954 ), 27 ignored
Branches     : 87.29% ( 1586/1817 ), 45 ignored
Functions    : 95.01% ( 343/361 ), 8 ignored
Lines        : 92.56% ( 3072/3319 )
=================================================================
@pvdz
Copy link
Contributor Author

pvdz commented Jul 11, 2016

I've given this a go. Moved every domain function that only concerned itself with numbers to asmjs. Effectively I moved:

  asmdomain_addRange,
  asmdomain_containsValue,
  asmdomain_createRange,
  asmdomain_createValue,
  asmdomain_createRangeZeroToMax,
  asmdomain_getValue,
  asmdomain_intersection,
  asmdomain_isSolved,
  asmdomain_isUndetermined,
  asmdomain_isValue,
  asmdomain_max,
  asmdomain_min,
  asmdomain_removeGte,
  asmdomain_removeLte,
  asmdomain_removeValue,
  asmdomain_sharesNoElements,
  asmdomain_size,

The results ... give us no significant improvements.

Maybe that's because Chrome (so v8) doesn't actively support asm.js. But since it's just good at what it does it picks up on the asm.js stuff anyways, and was already fast. The actual algorithm changes weren't that significant.

This may be a different story for array domains. But that also entails managing memory and that's not that trivial for arrays with an upper limit of 100000000 elements. That would mean requesting (4*100000000/(1024*1024))=381mb to be totally safe. And where do you put the limit. Some further investigation is in order because it's not very likely to hit the worse case (that's when you literally remove every even number from the SUB,SUP domain). We can get some more realistic numbers with profiling real world cases.

Still, you need to figure out what to do when you do hit that limit. You can't really request more memory in asmjs (you can in wasm, apparently, but that's a different story) so maybe return an error code and fall back to slow(er) paths?

@pvdz
Copy link
Contributor Author

pvdz commented Jul 11, 2016

Note that, even on chrome, the bigger win with moving more domain manipulation stuff to asmjs would come from doing memory management ourselves, on ArrayBuffers. That probably still applies, though we could do that without asmjs (but hey).

@pvdz pvdz mentioned this issue Jul 15, 2016
@pvdz
Copy link
Contributor Author

pvdz commented Oct 17, 2016

Tried this for a bit. No significant improvement. A next step could be that this is completely rewritten to fit in the asmjs paradigm but that's food for thought for another day.

@pvdz pvdz closed this as completed Oct 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant