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

[Web Viewer] Refactor NodeLoader#load method #183

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

akovalev
Copy link
Contributor

@akovalev akovalev commented Jan 3, 2019

Scope

Having read the code of OctreeViewer component, I realised that it was pretty hard to grasp what's going on in its nodesUpdate method. That's why I decided to abstract away the logic responsible for both splitting nodes into multiple batches and scheduling fetch requests so that there's no more than concurrent requests at a given moment of time into NodeLoader#load method.

Implementation

In order to achieve above-mentioned goal, new class called AsyncTaskQueue was introduced and integrated into NodeLoader. I believe it's better to review this PR commit by commit.

Also I have slightly updated README as it took me some time to figure out how to start the web viewer's client locally.

@akovalev akovalev force-pushed the viewer/async-queue branch from 76281a2 to 0561800 Compare January 3, 2019 14:42
the nodes into multiple batches is done by NodeLoader
Itself rather than its caller

replace now with performance.now

it was somehow lost when resolving conflicts
@akovalev akovalev force-pushed the viewer/async-queue branch from 8dd0f7c to b7df6ad Compare January 3, 2019 17:48
@SirVer SirVer requested a review from pdubroy January 7, 2019 10:16
Copy link
Contributor

@pdubroy pdubroy left a comment

Choose a reason for hiding this comment

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

Thanks for the cleanup! Looks pretty good to me. Generally I prefer to use async/await rather than dealing with promises directly, as I think it makes the control flow more readable. Most of my comments are related to that.

@@ -18,7 +18,7 @@ The project consist of a root crate that can build and read octrees on disk and
### Creating Octrees

In the root of the repo, run `cargo build --release`.
Then use `target/release/build_octree` to generate an octree out of a PLY file.
Then use `target/release/build_octree` to generate an octree out of a PLY file (`binary_little_endian` format). Sample files can be found [here](http://www.isi.imi.i.u-tokyo.ac.jp/~rodola/data.html)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

this.pendingCount = 0;
}

public addTask(fn: () => Promise<T>): Promise<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd write this as:

public async addTask(fn: () => Promise<T>): T {
  ...
}

material: THREE.ShaderMaterial,
nodes: NodeData[],
onNewNodeData: () => void
): Promise<void[]> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to return void[]? Assuming I understand this correctly, something like the following might be cleaner:

public async load(/* ... */) {
  await Promise.all(/* ... */);
}

@@ -325,39 +347,11 @@ export class OctreeViewer {

private nodesUpdate(nodeIds: string[]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer to write this as:

private async nodesUpdate(nodeIds: string[]) {
  ...
}

if (this.batches.length == 0 || this.currentlyLoading > 2) {
return;
}
this.currentlyLoading += 1;
this.nodeLoader
Copy link
Contributor

Choose a reason for hiding this comment

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

...then you should be able to write this as:

await this.nodeLoader.load(/* ... *);
onsole.log(`nodeUpdate took ${performance.now() - start}ms.`);

the readability of APIs exposed by both OctreeViewer
and AsyncTaskQueue classes
@akovalev
Copy link
Contributor Author

@pdubroy thanks for your feedback, I tried to incorporate it in 10d8417

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants