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

repeated parsing of file directories by every getImage call #449

Open
jcphill opened this issue Dec 12, 2024 · 1 comment
Open

repeated parsing of file directories by every getImage call #449

jcphill opened this issue Dec 12, 2024 · 1 comment

Comments

@jcphill
Copy link
Contributor

jcphill commented Dec 12, 2024

As shown below, every call to getImage() calls await this.parseFileDirectoriesPerFile() without using the result. parseFileDirectoriesPerFile() saves the result in this.fileDirectoriesPerFile but that variable is never referenced. The result is that every call to getImage() calls parseFileDirectoryAt() for every file for no reason.

geotiff.js/src/geotiff.js

Lines 613 to 634 in af0421b

this.fileDirectoriesPerFile = null;
this.fileDirectoriesPerFileParsing = null;
this.imageCount = null;
}
async parseFileDirectoriesPerFile() {
const requests = [this.mainFile.parseFileDirectoryAt(this.mainFile.firstIFDOffset)]
.concat(this.overviewFiles.map((file) => file.parseFileDirectoryAt(file.firstIFDOffset)));
this.fileDirectoriesPerFile = await Promise.all(requests);
return this.fileDirectoriesPerFile;
}
/**
* Get the n-th internal subfile of an image. By default, the first is returned.
*
* @param {number} [index=0] the index of the image to return.
* @returns {Promise<GeoTIFFImage>} the image at the given index
*/
async getImage(index = 0) {
await this.getImageCount();
await this.parseFileDirectoriesPerFile();

@jcphill
Copy link
Contributor Author

jcphill commented Dec 16, 2024

Just to note, this only affects the MultiGeoTIFF class (overviews in separate files). The single-file case looks OK.

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

No branches or pull requests

1 participant