Skip to content

Conversation

@knollengewaechs
Copy link
Contributor

@knollengewaechs knollengewaechs commented Nov 10, 2025

URL of deployed dev instance (used for testing):

Steps to test:

  • test that the following still works:
    • all view modes (flight, orthogonal, oblique)
    • affine transformations
    • drag and drop skeleton nodes
    • loading of ad-hoc meshes
    • area measurement
    • brushing

TODOs:

  • maybe have a look at other places and remove Float32Arrays there, too

Issues:


(Please delete unneeded items, merge only when none are left open)

  • Added changelog entry (create a $PR_NUMBER.md file in unreleased_changes or use ./tools/create-changelog-entry.py)
  • Added migration guide entry if applicable (edit the same file as for the changelog)
  • Updated documentation if applicable
  • Adapted wk-libs python client if relevant API parts change
  • Removed dev-only changes like prints and application.conf edits
  • Considered common edge cases
  • Needs datastore update after deployment

@knollengewaechs knollengewaechs self-assigned this Nov 10, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 10, 2025

📝 Walkthrough

Walkthrough

Replaces Float32Array/typed-array defaults with plain JavaScript arrays across the mjs utilities and related viewers, introduces explicit Vector16/Matrix4x4 type exports, and updates multiple public signatures and local typings to use generic Array<number> / concrete Vector2/Vector3 types.

Changes

Cohort / File(s) Summary
Core mjs module & types
frontend/javascripts/libs/mjs.ts, frontend/javascripts/types/mjs.d.ts
Add Vector16 and Matrix4x4 exports; replace many typed-array allocations with plain Array<number>; broaden public signatures to accept Array<number> / Int32Array where applicable; remove Vector2Like/Vector3Like and use concrete Vector2/Vector3 types; normalize helper overloads and internal allocations.
Viewer constants & API internals
frontend/javascripts/viewer/constants.ts, frontend/javascripts/viewer/api/api_latest.ts
Change Identity4x4 from Float32Array to Matrix4x4 (plain array); switch internal matrix construction in _createTransformsFromSpecs from typed arrays to plain 16-element arrays; adjust type-only imports to mjs.
Geometry, plane, rotation helpers, and bucket logic
frontend/javascripts/viewer/geometries/helper_geometries.ts, frontend/javascripts/viewer/geometries/plane.ts, frontend/javascripts/viewer/model/helpers/rotation_helpers.ts, frontend/javascripts/viewer/model/bucket_data_handling/bucket_traversals.ts, frontend/javascripts/viewer/model/bucket_data_handling/bucket_picker_strategies/flight_bucket_picker.ts, frontend/javascripts/viewer/model/bucket_data_handling/bucket_picker_strategies/oblique_bucket_picker.ts
Add/clarify local type annotations (Vector3, number), replace V3.equals usage with V3.isEqual with explicit subarray conversion, remove ts-ignore by adding explicit casts, factor negation into named constant, and add typed reduce/map callbacks.
Changelog
unreleased_changes/9059.md
Add note describing removal of Float32Array defaults and switch to plain arrays for mjs module.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Areas to pay extra attention:
    • frontend/javascripts/libs/mjs.ts — public signature changes (transformPointsAffine, transformPoints, inverse, extractTranslation, V2/V3 helpers) and propagation to callers.
    • frontend/javascripts/types/mjs.d.ts — ensure new Vector16/Matrix4x4 aliases match runtime shapes and exported signatures.
    • Places previously relying on typed-array identity (e.g., equality checks, binary interop) for subtle behavioral differences.

Possibly related PRs

Suggested labels

frontend, enhancement, performance

Suggested reviewers

  • philippotto
  • daniel-wer

Poem

🐰 I swapped the floats for roads of plain,
Arrays that hop, no typed-array train.
Vectors now cuddle in neat little rows,
M4x4 and friends — off the old rails they go! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Cleanup mjs module' accurately summarizes the main change: refactoring the mjs module to replace Float32Array allocations with plain arrays.
Linked Issues check ✅ Passed The PR successfully implements the core objective from #8666: reducing Float32Array usage in the mjs module and replacing default allocations with plain arrays while maintaining the optional output parameter pattern.
Out of Scope Changes check ✅ Passed All changes are directly related to issue #8666. Type refinements and import adjustments in api_latest, constants, and other files are necessary consequences of the mjs module refactoring.
Description check ✅ Passed The pull request description clearly relates to the changeset. It provides deployment testing instructions, specifies what to test, references the fixed issue (#8666), and includes checklist items related to the changes (changelog added, other items marked done).
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cleanup-mjs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

fm3 and others added 7 commits November 10, 2025 12:25
### Steps to test:
- CI

--
- [x] Needs datastore update after deployment

---------

Co-authored-by: MichaelBuessemeyer <[email protected]>
### URL of deployed dev instance (used for testing):
- https://datasetliststorage.webknossos.xyz

### Steps to test:
- hit `yarn enable-storage-scan`, wait for next tick (every 10 minutes,
1 minute after startup, can be changed in application.conf)
- after scan, see used storage in dashboard

### TODOs:
- [x] Hide column if orga total used storage is 0
- [x] Gather feedback on tooltip wording and coulmn name (size vs
storage vs ??) ->
https://scm.slack.com/archives/C5AKLAV0B/p1761836548789409
- [x] CI (api types mismatch?)

### Issues:
- contributes to #9005

------
- [x] Added changelog entry (create a `$PR_NUMBER.md` file in
`unreleased_changes` or use `./tools/create-changelog-entry.py`)
- [x] Removed dev-only changes like prints and application.conf edits
- [x] Considered [common edge
cases](../blob/master/.github/common_edge_cases.md)

---------

Co-authored-by: Charlie Meister <[email protected]>
Co-authored-by: Charlie Meister <[email protected]>
Co-authored-by: MichaelBuessemeyer <[email protected]>
### URL of deployed dev instance (used for testing):
- https://___.webknossos.xyz

### Steps to test:
- Open a publicly available annotation without being logged in -> no
error toast :)
- I tested this on commit ea18578 (the
merge of #8961)

### TODOs:
- [ ] test on current master. Wasnt able to run wk locally this morning
(https://scm.slack.com/archives/C5AKLAV0B/p1762768096605689)

### Issues:
- fixes https://scm.slack.com/archives/C5AKLAV0B/p1762764001604969
- follow-up for #8961 

------
(Please delete unneeded items, merge only when none are left open)
- [ ] Added changelog entry (create a `$PR_NUMBER.md` file in
`unreleased_changes` or use `./tools/create-changelog-entry.py`)
- [ ] Added migration guide entry if applicable (edit the same file as
for the changelog)
- [ ] Updated [documentation](../blob/master/docs) if applicable
- [ ] Adapted [wk-libs python
client](https://github.com/scalableminds/webknossos-libs/tree/master/webknossos/webknossos/client)
if relevant API parts change
- [ ] Removed dev-only changes like prints and application.conf edits
- [ ] Considered [common edge
cases](../blob/master/.github/common_edge_cases.md)
- [ ] Needs datastore update after deployment
@knollengewaechs knollengewaechs marked this pull request as ready for review November 10, 2025 17:04
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
frontend/javascripts/viewer/model/sagas/volumetracing_saga.tsx (1)

292-300: Strip debug logging before shipping.

This console.log will fire for every brush step and flood the browser console in production. Please remove it (or guard it behind a proper logger/debug flag) before merging.

-        console.log("Brushing between:", lastPosition, addToLayerAction.position);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 12861dd and d6e68c6.

📒 Files selected for processing (6)
  • frontend/javascripts/libs/mjs.ts (10 hunks)
  • frontend/javascripts/types/mjs.d.ts (0 hunks)
  • frontend/javascripts/viewer/api/api_latest.ts (2 hunks)
  • frontend/javascripts/viewer/constants.ts (2 hunks)
  • frontend/javascripts/viewer/model/bucket_data_handling/bucket_picker_strategies/flight_bucket_picker.ts (1 hunks)
  • frontend/javascripts/viewer/model/sagas/volumetracing_saga.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • frontend/javascripts/types/mjs.d.ts
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2024-11-22T17:18:04.217Z
Learnt from: dieknolle3333
Repo: scalableminds/webknossos PR: 8168
File: frontend/javascripts/oxalis/model/sagas/proofread_saga.ts:1039-1039
Timestamp: 2024-11-22T17:18:04.217Z
Learning: In `frontend/javascripts/oxalis/model/sagas/proofread_saga.ts`, when calling `getMagInfo`, the use of `volumeTracingLayer.resolutions` is intentional and should not be changed to `volumeTracingLayer.mags`.

Applied to files:

  • frontend/javascripts/viewer/model/sagas/volumetracing_saga.tsx
📚 Learning: 2024-11-22T17:18:43.411Z
Learnt from: dieknolle3333
Repo: scalableminds/webknossos PR: 8168
File: frontend/javascripts/oxalis/geometries/materials/plane_material_factory.ts:568-585
Timestamp: 2024-11-22T17:18:43.411Z
Learning: In the file `frontend/javascripts/oxalis/geometries/materials/plane_material_factory.ts`, the uniform name `allResolutions` should remain unchanged to maintain consistency with the shader code.

Applied to files:

  • frontend/javascripts/viewer/constants.ts
📚 Learning: 2025-07-22T12:56:47.507Z
Learnt from: daniel-wer
Repo: scalableminds/webknossos PR: 8787
File: frontend/javascripts/viewer/model/accessors/dataset_layer_transformation_accessor.ts:132-136
Timestamp: 2025-07-22T12:56:47.507Z
Learning: Three.js Vector3 has explicitly defined x, y, and z properties that can be safely accessed via dynamic string indexing when using union types like "x" | "y" | "z". The pattern `vector[axis] = value` where axis is "x" | "y" | "z" does not cause TypeScript strict mode errors because TypeScript can infer the property access is valid.

Applied to files:

  • frontend/javascripts/viewer/constants.ts
  • frontend/javascripts/libs/mjs.ts
🧬 Code graph analysis (5)
frontend/javascripts/viewer/model/sagas/volumetracing_saga.tsx (1)
frontend/javascripts/viewer/model/actions/volumetracing_actions.ts (1)
  • addToLayerAction (180-184)
frontend/javascripts/viewer/model/bucket_data_handling/bucket_picker_strategies/flight_bucket_picker.ts (2)
frontend/javascripts/libs/mjs.ts (1)
  • M4x4 (402-402)
frontend/javascripts/viewer/constants.ts (1)
  • Vector3 (15-15)
frontend/javascripts/viewer/api/api_latest.ts (2)
frontend/javascripts/libs/mjs.ts (1)
  • Matrix4x4 (33-33)
frontend/javascripts/types/mjs.d.ts (1)
  • Matrix4x4 (6-24)
frontend/javascripts/viewer/constants.ts (1)
frontend/javascripts/libs/mjs.ts (1)
  • Vector16 (15-32)
frontend/javascripts/libs/mjs.ts (2)
frontend/javascripts/types/mjs.d.ts (1)
  • Matrix4x4 (6-24)
frontend/javascripts/viewer/constants.ts (2)
  • Vector3 (15-15)
  • Vector2 (14-14)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: backend-tests
  • GitHub Check: build-smoketest-push

@knollengewaechs knollengewaechs marked this pull request as draft November 11, 2025 08:33
@knollengewaechs
Copy link
Contributor Author

knollengewaechs commented Nov 12, 2025

@ philippotto I exchanged every new initialization of float32arrays within the mjs module. I was hesitant about moving away from float32arrays in other places, e.g. api_latest. Do you think it makes sense to move to arrays/numbers there, too?

@knollengewaechs knollengewaechs marked this pull request as ready for review November 13, 2025 15:20
Copy link
Member

@philippotto philippotto left a comment

Choose a reason for hiding this comment

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

thank you for doing this!

const scaledPosition = V3.multiply(originalPosition, this.datasetScaleFactor);
// The offset is in world space already so no scaling is necessary.
const offsetPosition = V3.add(scaledPosition, positionOffset);
const offsetPosition: Vector3 = V3.add(scaledPosition, positionOffset);
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't the return value of V3.add automatically be Vector3?

// In addition, the variables stepX and stepY are initialized to either 1 or -1 indicating whether X and Y are
// incremented or decremented as the ray crosses voxel boundaries (this is determined by the sign of the x and y components of → v).
const [stepX, stepY, stepZ] = v.map((el) => Math.sign(el));
const [stepX, stepY, stepZ] = v.map((el: number) => Math.sign(el));
Copy link
Member

Choose a reason for hiding this comment

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

why is this change necessary?

Comment on lines +18 to +19
r?: Int32Array | Array<number> | null | undefined,
): Int32Array | Array<number> {
Copy link
Member

Choose a reason for hiding this comment

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

why is Int32Array necessary here?

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

Successfully merging this pull request may close these issues.

Clean up mjs module for vector calculation

4 participants