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: increase html-reporter performance #492

Closed
wants to merge 5 commits into from

Conversation

@KuznetsovRoman KuznetsovRoman force-pushed the HERMIONE-1138.perf branch 3 times, most recently from 8e4bef6 to 3a7cf13 Compare September 4, 2023 22:59
return resolvedUrls;
}

async function tryResolveUrl(url) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Рекурсивно проходит по всем вложенным .json базам. Если возникает ошибка при получении данных, возвращаем саму json-базу. Помимо "ничего не сломать", фоллбэк нужен для драфт отчетов

const results = await Promise.all(urls.map(tryResolveUrl));

results.forEach(({jsonUrls, dbUrls}) => {
resolvedUrls.push(...jsonUrls.concat(dbUrls));
Copy link
Member Author

Choose a reason for hiding this comment

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

Все urls вставляются в один массив, потому что это позволяет не ломать API слияния отчетов

@@ -131,7 +131,8 @@ export async function saveStaticFilesToReportDir(htmlReporter: HtmlReporter, plu
copyToReportDir(destPath, ['report.min.js', 'report.min.css'], staticFolder),
fs.copy(path.resolve(staticFolder, 'index.html'), path.resolve(destPath, 'index.html')),
fs.copy(path.resolve(staticFolder, 'icons'), path.resolve(destPath, 'icons')),
fs.copy(require.resolve('@gemini-testing/sql.js'), path.resolve(destPath, 'sql-wasm.js')),
Copy link
Member Author

Choose a reason for hiding this comment

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

-2 МБ

@@ -131,7 +131,8 @@ export async function saveStaticFilesToReportDir(htmlReporter: HtmlReporter, plu
copyToReportDir(destPath, ['report.min.js', 'report.min.css'], staticFolder),
fs.copy(path.resolve(staticFolder, 'index.html'), path.resolve(destPath, 'index.html')),
fs.copy(path.resolve(staticFolder, 'icons'), path.resolve(destPath, 'icons')),
fs.copy(require.resolve('@gemini-testing/sql.js'), path.resolve(destPath, 'sql-wasm.js')),
fs.copy(require.resolve('@gemini-testing/sql.js/dist/sql-wasm.js'), path.resolve(destPath, 'sql-wasm.js')),
Copy link
Member Author

Choose a reason for hiding this comment

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

  • 56 КБ

@@ -131,7 +131,8 @@ export async function saveStaticFilesToReportDir(htmlReporter: HtmlReporter, plu
copyToReportDir(destPath, ['report.min.js', 'report.min.css'], staticFolder),
fs.copy(path.resolve(staticFolder, 'index.html'), path.resolve(destPath, 'index.html')),
fs.copy(path.resolve(staticFolder, 'icons'), path.resolve(destPath, 'icons')),
fs.copy(require.resolve('@gemini-testing/sql.js'), path.resolve(destPath, 'sql-wasm.js')),
fs.copy(require.resolve('@gemini-testing/sql.js/dist/sql-wasm.js'), path.resolve(destPath, 'sql-wasm.js')),
fs.copy(require.resolve('@gemini-testing/sql.js/dist/sql-wasm.wasm'), path.resolve(destPath, 'sql-wasm.wasm')),
Copy link
Member Author

Choose a reason for hiding this comment

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

  • 620 КБ


export function groupMeta({group, groupKey, ...restArgs}) {
export function groupMeta({group, groupKey, diff = group, ...restArgs}) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Здесь и далее diff в функциях - место, куда нужно записывать изменения. По иерархии такие diff равны тому, чему устанавливаются по умолчанию (в данном случае, group)

Comment on lines +23 to +26
group: group.byKey[groupKey],
result,
value,
diff: diff.byKey[groupKey]
Copy link
Member Author

Choose a reason for hiding this comment

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

Так что дальше в функции они прокидываются так же, как и сами их read-only сущности из state

Comment on lines 26 to 27
case actionNames.INIT_GUI_REPORT:
case actionNames.INIT_STATIC_REPORT: {
Copy link
Member Author

Choose a reason for hiding this comment

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

В этом action, tree не является частью стейта, так что тут можно мутировать его напрямую, что гораздо проще

@@ -1,4 +1,4 @@
import {findLast} from 'lodash';
Copy link
Member Author

Choose a reason for hiding this comment

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

Тут я перенес только action из статического отчета, потому что в gui профит слабый, да и логика там становится намного сложнее, так что оно того не стоит

Copy link
Member Author

Choose a reason for hiding this comment

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

Я тут пытался расположить обработку action в том же порядке, но тем не менее, в секции с reduce он отрезолвился плохо. Там можно не смотреть, оставил как было.

Редьюсер распилен на две части:

Первая (статика, без immer.produce):

switch (action.type) {
    case actionNames...
        ....
        return applyStateUpdate(state, diff)

Вторая (gui, с immer.produce):

return produce(state, draft => {
    switch (action.type) {
        case actionNames...
            ....
           break;
})`

Comment on lines +9 to +10
<link rel="preload" href="databaseUrls.json" as="fetch" crossorigin="anonymous"/>
<link rel="preload" href="sql-wasm.wasm" as="fetch" crossorigin="anonymous"/>
Copy link
Member Author

Choose a reason for hiding this comment

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

Потоков у браузера хватает, чтобы грузить это все вместе с report.min.js параллельно.

@KuznetsovRoman KuznetsovRoman force-pushed the HERMIONE-1138.perf branch 2 times, most recently from ebb880d to c91bcc0 Compare September 5, 2023 10:31
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.

1 participant