Unexpected module.runSetters wrapping
- Dominant language
- JavaScript
- Stars
- 740
- Forks
- 29
- PR merge metrics
- No merged PRs in 30d
Description
I am using reify 0.20.12 from Meteor and am importing vec3 from [gl-matrix](https://github.com/toji/gl-matrix).
My issue is that this [function](https://github.com/toji/gl-matrix/blob/master/src/vec3.js#L335):
``` js
/**
* Normalize a vec3
*
* @param {vec3} out the receiving vector
* @param {ReadonlyVec3} a vector to normalize
* @returns {vec3} out
*/
export function normalize(out, a) {
let x = a[0];
let y = a[1];
let z = a[2];
let len = x * x + y * y + z * z;
if (len > 0) {
len = 1 / Math.sqrt(len);
}
out[0] = a[0] * len;
out[1] = a[1] * len;
out[2] = a[2] * len;
return out;
}
```
once run through reify becomes:
```js
function normalize(out, a) {
var x = a[0];
var y = a[1];
var z = a[2];
var len = x * x + y * y + z * z;
if (len > 0) {
module.runSetters(len = 1 / Math.sqrt(len)); // <----- unexpected module.runSetters
out[0] = a[0] * len;
out[1] = a[1] * len;
out[2] = a[2] * len;
}
return out;
}
```
I suspect the issue triggered because another `len` is later [exported ](https://github.com/toji/gl-matrix/blob/master/src/vec3.js#L777) :
``` js
/**
* Alias for {@link vec3.length}
* @function
*/
export const len = length;
```
being a heavy 3D application, normalize is called 100s or 1000s of times per frame and this needless callback is really killing performance. Is this expected? Any way to avoid it?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with src/vec3.js, especially normalize and the later export const len, and reproduce the transformation from the shown input. Trace why the assignment to len becomes module.runSetters; done means the generated normalize code no longer adds that wrapper while preserving module exports.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100