-
Notifications
You must be signed in to change notification settings - Fork 26
feat: 增加编译耗时的统计 #657
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
base: main
Are you sure you want to change the base?
feat: 增加编译耗时的统计 #657
Changes from all commits
57146a6
42ec597
d7f721d
8a68afd
553573a
93dd1e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Shader 编译测试 - demo</title> | ||
| <style> | ||
| html, body, div, canvas { margin: 0; padding: 0; } | ||
| .container { | ||
| visibility: hidden; | ||
| opacity: 0; | ||
| width: 188px; | ||
| height: 334px; | ||
| position: fixed; | ||
| bottom: 0%; | ||
| left: 50%; | ||
| transform: translate(-50%, 0) scale(0); | ||
| transition: transform 0.5s ease-in-out; | ||
| background-color: rgba(0,0,0,255); | ||
| } | ||
| .container.active { | ||
| visibility: visible; | ||
| z-index: -1; | ||
| opacity: 1; | ||
| transform: translate(-50%, 0) scale(1); | ||
| } | ||
| ul { | ||
| background-color: rgba(255,255,255,0.5); | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <dl id="J-statistic"></dl> | ||
| <div> | ||
| <button id="J-button" style="height: 32px; width: 100px;">播放</button> | ||
| </div> | ||
| <div class="container" id="J-container"></div> | ||
|
|
||
| <script type="module" src="../src/shader-compile.ts"></script> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import type { Composition } from '@galacean/effects'; | ||
| import { Player } from '@galacean/effects'; | ||
| import '@galacean/effects-plugin-spine'; | ||
|
|
||
| // 大量粒子 | ||
| // const json = 'https://mdn.alipayobjects.com/mars/afts/file/A*aCeuQ5RQZj4AAAAAAAAAAAAADlB4AQ'; | ||
| // 新年烟花 | ||
| const json = [ | ||
| 'https://gw.alipayobjects.com/os/gltf-asset/mars-cli/ILDKKFUFMVJA/1705406034-80896.json', | ||
| 'https://mdn.alipayobjects.com/graph_jupiter/afts/file/A*qTquTKYbk6EAAAAAAAAAAAAADsF2AQ', | ||
| ]; | ||
| // 混合测试 | ||
| // const json = [ | ||
| // 'https://mdn.alipayobjects.com/mars/afts/file/A*QyX8Rp-4fmUAAAAAAAAAAAAADlB4AQ', | ||
| // 'https://mdn.alipayobjects.com/mars/afts/file/A*bi3HRobVsk8AAAAAAAAAAAAADlB4AQ', | ||
| // 'https://mdn.alipayobjects.com/graph_jupiter/afts/file/A*sEdkT5cdXGEAAAAAAAAAAAAADsF2AQ', | ||
| // ]; | ||
| // 塔奇 | ||
| // const json = 'https://mdn.alipayobjects.com/mars/afts/file/A*uU2JRIjcLIcAAAAAAAAAAAAADlB4AQ'; | ||
| // const json = 'https://gw.alipayobjects.com/os/gltf-asset/mars-cli/TAJIINQOUUKP/-799304223-0ee5d.json'; | ||
| const container = document.getElementById('J-container'); | ||
|
|
||
| document.getElementById('J-button')!.addEventListener('click', () => { | ||
|
Comment on lines
+21
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve error handling for DOM element selection Consider adding checks to ensure DOM elements exist before using them: const container = document.getElementById('J-container');
const button = document.getElementById('J-button');
if (!container || !button) {
console.error('Required DOM elements not found');
// Handle the error appropriately
return;
}
button.addEventListener('click', () => {
// ... existing code ...
});This approach prevents potential runtime errors and provides better error feedback. |
||
| (async () => { | ||
| try { | ||
| container?.classList.add('active'); | ||
|
|
||
| const player = new Player({ | ||
| container, | ||
| // renderFramework: 'webgl2', | ||
| }); | ||
| const compositions = await player.loadScene(Array.isArray(json) ? json : [json]) as unknown as Composition[]; | ||
|
Comment on lines
+28
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refine type handling and error management
|
||
|
|
||
| compositions.forEach(composition => { | ||
| const dt = document.createElement('dt'); | ||
|
|
||
| dt.innerHTML = `>>> composition: ${composition.name}`; | ||
| document.getElementById('J-statistic')?.appendChild(dt); | ||
|
|
||
| for (const key in composition.statistic) { | ||
| const p = document.createElement('dd'); | ||
|
|
||
| // @ts-expect-error | ||
| p.innerHTML = `${key}: ${composition.statistic[key]}`; | ||
| document.getElementById('J-statistic')?.appendChild(p); | ||
| } | ||
| }); | ||
|
Comment on lines
+34
to
+47
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance performance, security, and error handling in statistics display
|
||
| } catch (e) { | ||
| console.error('biz', e); | ||
| } | ||
| })(); | ||
| }); | ||
|
Comment on lines
+23
to
+52
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve overall structure and error handling
These changes will improve the code's structure, error handling, and user experience. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ export default defineConfig(({ mode }) => { | |
| 'dynamic-image': resolve(__dirname, 'html/dynamic-image.html'), | ||
| 'dynamic-video': resolve(__dirname, 'html/dynamic-video.html'), | ||
| 'render-level': resolve(__dirname, 'html/render-level.html'), | ||
| 'shader-compile': resolve(__dirname, 'html/shader-compile.html'), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Compilation time tracking not implemented The Analysis chainReminder: Implement compilation time tracking While this configuration change correctly includes the new shader-compile.html file, ensure that the actual implementation of compilation time tracking is present in the HTML file or its associated JavaScript. This is crucial to meet the PR objective of adding compilation time statistics. To verify the implementation of compilation time tracking, let's check the contents of the shader-compile.html file: Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check for compilation time tracking implementation in shader-compile.html
# Search for keywords related to time tracking in the shader-compile.html file
rg -i "time|duration|performance|measure" "html/shader-compile.html"
Length of output: 228 Script: #!/bin/bash
# Description: Locate the shader-compile.html file in the repository
fd "shader-compile\.html$" .
Length of output: 75 Script: #!/bin/bash
# Description: Verify compilation time tracking implementation in shader-compile.html
rg -i "time|duration|performance|measure" "./web-packages/demo/html/shader-compile.html"
Length of output: 88 |
||
| 'local-file': resolve(__dirname, 'html/local-file.html'), | ||
| 'post-processing': resolve(__dirname, 'html/post-processing.html'), | ||
| 'single': resolve(__dirname, 'html/single.html'), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider enhancing CSS for better maintainability and user experience.
While the current CSS is functional, there are opportunities for improvement:
rgba(0,0,0,255)), which might affect content visibility.Consider the following improvements:
<style> html, body, div, canvas { margin: 0; padding: 0; } + :root { + --container-width: 188px; + --container-height: 334px; + --container-bg: rgba(0, 0, 0, 0.8); + --transition-duration: 0.5s; + } .container { visibility: hidden; opacity: 0; - width: 188px; - height: 334px; + width: var(--container-width); + height: var(--container-height); position: fixed; bottom: 0%; left: 50%; transform: translate(-50%, 0) scale(0); - transition: transform 0.5s ease-in-out; - background-color: rgba(0,0,0,255); + transition: transform var(--transition-duration) ease-in-out, opacity var(--transition-duration) ease-in-out; + background-color: var(--container-bg); } .container.active { visibility: visible; - z-index: -1; + z-index: 1; opacity: 1; transform: translate(-50%, 0) scale(1); } ul { - background-color: rgba(255,255,255,0.5); + background-color: rgba(255, 255, 255, 0.8); } </style>These changes improve readability, maintainability, and potentially the visual appearance of the interface.
Committable suggestion