Giter VIP home page Giter VIP logo

Comments (4)

kripken avatar kripken commented on August 18, 2024

You can copy them in now using typed array .set(). (Also, you likely anyhow do not want to do processing on a clamped array for speed purposes, I think?)

asm.js currently wants to bind tightly to its typed array, for speed purposes, so passing over a new one each call would not fit that model.

from validator.

pyalot avatar pyalot commented on August 18, 2024

Not acceptable. Man ctypes, actually useful FFI. Passing in arrays is a mandatory feature.

asm.js currently wants to bind tightly to its typed array, for speed purposes, so passing over a new one each call would not fit that model.

The fuck?!

from validator.

kripken avatar kripken commented on August 18, 2024

The asm.js model is very simple: a singleton typed array for data storage. This is what makes it super-easy to optimize to native-like speeds.

If the asm spec allowed passing in typed arrays, accessing them would necessary entail the usual type checks, bound checks, bailouts, etc. - meaning it would not run at typical asm.js speed. It could still run pretty fast, because modern JS engines are fast. But it couldn't benefit from the predictable level of performance you can expect from asm.js.

But the important thing is that the singleton typed array in asm.js is not owned by it - it's a normal typed array, accessible from outside the asm module as well. That means you can access other typed arrays in outside code, and that code can also access the asm.js typed array,

var asm = (function asmModule(buffer, stdlib, ffi) {
  "use asm";
  // ...
})(buffer, stdlib, ffi);

function extFunction(newArray) {
  // operations on both buffer and newArray
}

That extFunction can run very quickly. Not typical asm.js speed, but still, if all it does is access some typed arrays and so basic math, that is stuff that modern JS engines can optimize well. And that speed is basically the limit - you couldn't get better from writing that code in asm.

Therefore, there isn't a strong reason to add passing in new arrays to asm code.

from validator.

 avatar commented on August 18, 2024

With non-trivial effort (and thus significant justification required), asm.js modules could have a second heap:

function f(stdlib, ffis, buffer1, buffer2) { "use asm"; ... }

The existing change heap asm.js extension could then be used to arbitrarily swap buffer1 and buffer2. Thus, you could change-heap buffer2 to the result of getImageData() and then pound on this in a subsequent asm.js function call.

I'm not sure how this would be reflected in C++/Emscripten, though. In particular, every heap access would need to statically know which heap to load from and there is no natural way I know of to express this in C++ since the memory model assumes a single linear address space. Some sort of extra annotations would be required (or a bunch of EM_ASM).

from validator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.