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

Why is it much slower than the PSD library? #171

Open
Sunge8081 opened this issue Apr 22, 2024 · 5 comments
Open

Why is it much slower than the PSD library? #171

Sunge8081 opened this issue Apr 22, 2024 · 5 comments
Assignees

Comments

@Sunge8081
Copy link

import { readPsd } from 'ag-psd';
import * as fs from 'fs';
const PSD = require('psd');

let file="/Users/xiaobaozi/Downloads/模板/批量模板/模板1/主图.psd" //size≈196MB
let buf=fs.readFileSync(file)


console.time("ag-psd:readPsd")
//@ts-ignore
const psd = readPsd(buf.buffer,{ skipLayerImageData: true, skipCompositeImageData: true, skipThumbnail: true });
console.timeEnd("ag-psd:readPsd")

console.time("PSD:readPsd")
const psd2 = PSD.fromFile(file);
psd2.parse();
console.timeEnd("PSD:readPsd")

console:
ag-psd:readPsd: 2.453s
PSD:readPsd: 909.677ms

@Agamnentzar Agamnentzar self-assigned this Apr 22, 2024
@Agamnentzar
Copy link
Owner

I think it's because ag-psd is parsing the whole file in readPsd call, and then you have entire structure available to you, psd library is only doing initial parsing and then it's processing the file when you're calling api functions on it, so the processing time is spread around in all of the functions. In this example you're not reading anything from the file, so the psd library is skipping most of the work.

That said 2.453s is a lot of time, if it's possible for you to share the file I could look into performance issues and maybe improve it.

@826327700
Copy link

Is it possible to set ReadOptions and discard some options based on user customization to make reading psd faster?

@826327700
Copy link

我认为这是因为ag-psd在 readPsd 调用中解析整个文件,然后你就有了可用的整个结构,psd库只进行初始解析,然后当你调用 api 函数时它正在处理文件,所以处理时间是分布在所有功能中。在此示例中,您没有从文件中读取任何内容,因此psd库将跳过大部分工作。

也就是说 2.453 秒是很多时间,如果您可以共享该文件,我可以研究性能问题并可能改进它。

This is my test psd file: https://gallery-dev-1318352346.cos.ap-guangzhou.myqcloud.com/upload/dev/gallery/public/2024-01-10/%E4%B8%BB%E5%9B%BE.psd

@Agamnentzar
Copy link
Owner

Just released version 20.1.0 with fix for the issue.

It was actually mostly decoding that huge 46MB xmpMetadata field, I improved utf-8 decoding/encoding, and now it should be really fast.

@826327700
Copy link

Just released version 20.1.0 with fix for the issue.

It was actually mostly decoding that huge 46MB xmpMetadata field, I improved utf-8 decoding/encoding, and now it should be really fast.

Your improvement was so timely, and now the reading time has been reduced to within 100ms. It's great, thank you! It is very helpful for my current work!

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

3 participants