donmccurdy / donmccurdy/glTF-Transform

Implement `listFoo()` methods using iterators

Open
#685 1 comment 0 reactions 0 assignees View on GitHub
feature package:core performance
Dominant language
TypeScript
Stars
2k
Forks
206
Avg merge
2d 2h
Merged PRs (30d)
16

Description

Currently methods like `root.listNodes()`, `mesh.listPrimitives()`, and `texture.listParents()` all build and return a new array of their results. Most use of these methods throughout the library is simply iterating over the results, and creating these arrays is mostly overhead:

https://github.com/donmccurdy/property-graph/blob/c45c943fe1594a8b0dcaa5b7203a943b45c13c6b/src/graph-node.ts#L230-L233

I'd like to re-implement these methods using [iterators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator), instead. Most of the changes would be in the [`property-graph`](https://github.com/donmccurdy/property-graph) module.

Implications:

- Cannot call .forEach, .filter, .map on iterable, must use Array.from or `for ... of`
- Mutating the underlying list during iteration may have undefined results

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.