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

FBXLoader - Speed up getTimesForAllAxes #20906

Merged
merged 1 commit into from Dec 21, 2020
Merged

Conversation

Kimbatt
Copy link
Contributor

@Kimbatt Kimbatt commented Dec 19, 2020

Description

This pull request speeds up the getTimesForAllAxes function of FBXLoader.

Currently, the duplicate removal part of the function is using Array.indexOf for each element, which is an O(n) operation (it needs to perform a linear search on the whole array).

times = times.sort( function ( a, b ) {

	return a - b;

} ).filter( function ( elem, index, array ) {

	return array.indexOf( elem ) == index;

} );

Doing this for each element of the array makes this part of the function have O(n^2) time complexity.
But since the array is already sorted, we can use an O(n) method to remove duplicates from it.
This can significantly reduce the loading time for files with long animations.

@mrdoob mrdoob added this to the r124 milestone Dec 21, 2020
@mrdoob mrdoob merged commit 6e21d44 into mrdoob:dev Dec 21, 2020
@mrdoob
Copy link
Owner

mrdoob commented Dec 21, 2020

Thanks!

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.

None yet

2 participants