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

perf-test: Replace fileType with fileSize #46

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions perf-test/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,15 @@ export default function Home() {

for (let i = 0; i < _count; i++) {
const _anim = animations[Math.floor(Math.random() * animations.length)];
const lottieURL = `${urlPrefix}${_anim}`;

const response = await fetch(lottieURL);
Copy link
Member

@hermet hermet Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fetching will not affect the loading time? if you think it's ignoreable, it's good to go.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It affects the loading time and light house score, will fix it soon. Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Size is not quite necessary, we can just remove the type.

const contentLength = response.headers.get('content-length');

newAnimationList.push({
name: _anim.split('/').pop()?.split('.')[0] || 'Unknown',
lottieURL: `${urlPrefix}${_anim}`,
location: `Type: ${_anim.split('/').pop()?.split('.')[1] || 'Unknown'}`,
lottieURL,
fileSize: `Size: ${contentLength ? (parseInt(contentLength) / 1024).toFixed(2) : 0}KB`,
});
}

Expand All @@ -243,20 +247,27 @@ export default function Home() {
setQueryStringParameter('seed', seed);
}

const loadSeed = (seed: string) => {
const loadSeed = async (seed: string) => {
const nameList = atob(seed).split(',');
console.log(nameList);
const newAnimationList = nameList.map((name: string) => {
const _anim = animations.find((anim) => anim === `${name.trim()}.json`) || animations[0];

return {
name: name,
lottieURL: `${urlPrefix}${_anim}`,
location: `Type: ${_anim.split('/').pop()?.split('.')[1] || 'Unknown'}`,
};
});
const newAnimationList = [];

for (let i = 0; i < nameList.length; i++) {
const _anim = animations.find((anim) => anim === `${nameList[i]}.json`) || animations[0];
const lottieURL = `${urlPrefix}${_anim}`;

setAnimationList(newAnimationList);
const response = await fetch(lottieURL);
const contentLength = response.headers.get('content-length');

newAnimationList.push({
name: _anim.split('/').pop()?.split('.')[0] || 'Unknown',
lottieURL,
fileSize: `Size: ${contentLength ? (parseInt(contentLength) / 1024).toFixed(2) : 0}KB`,
});
}

// @ts-ignore
await setAnimationList([]);
await setAnimationList(newAnimationList);
}

const spawnAnimation = () => {
Expand All @@ -269,7 +280,7 @@ export default function Home() {
const randomIndex = Math.floor(Math.random() * animationList.length);
animationList[randomIndex].lottieURL = text;
animationList[randomIndex].name = text.split('/').pop()?.split('.')[0] || 'Unknown';
animationList[randomIndex].location = `Type: ${text.split('/').pop()?.split('.')[1] || 'Unknown'}`;
animationList[randomIndex].fileSize = `Type: ${text.split('/').pop()?.split('.')[1] || 'Unknown'}`;
setAnimationList(animationList.slice());

setTimeout(() => {
Expand Down Expand Up @@ -492,7 +503,7 @@ export default function Home() {
)
}
<h3 className={`mt-6 text-lg font-semibold leading-8 tracking-tight text-white max-w-[${size.width}px] overflow-hidden`}>{anim.name}</h3>
<p className={`text-sm leading-6 text-gray-500 max-w-[${size.width}px] overflow-hidden`}>{anim.location}</p>
<p className={`text-sm leading-6 text-gray-500 max-w-[${size.width}px] overflow-hidden`}>{anim.fileSize}</p>
</li>
))}
</ul>
Expand Down