-
Notifications
You must be signed in to change notification settings - Fork 98
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
base: master
Are you sure you want to change the base?
Conversation
when scheduling the execution of async operations
76281a2
to
0561800
Compare
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
during the development
8dd0f7c
to
b7df6ad
Compare
There was a problem hiding this 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) |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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[]> { |
There was a problem hiding this comment.
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[]) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
Scope
Having read the code of
OctreeViewer
component, I realised that it was pretty hard to grasp what's going on in itsnodesUpdate
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 intoNodeLoader#load
method.Implementation
In order to achieve above-mentioned goal, new class called
AsyncTaskQueue
was introduced and integrated intoNodeLoader
. 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.