Refactor global init code and add more comments#33755
Conversation
|
The "autofocus-end" and "dir=auto" all work as expected: And the performance trace: |
95000ee to
0b0ff57
Compare
0b0ff57 to
c8b753e
Compare
c8b753e to
2e42865
Compare
|
I'm not sure I like the "global" name used here. It seems superflous. Why is it named like that? |
I think the meaning is accurate. Because there are "global" event handlers and init function callers (they affect all elements), and it matches If you have better and accurate names, please advise. And since these names are unique, even we keep them, we could always be able to easily change them by a search&replace in the future. |
621bd65 to
47244e9
Compare
47244e9 to
9208f4f
Compare
| for (let i = 0; i < 20 && i < this.results.length; i++) { | ||
| // eslint-disable-next-line no-console | ||
| console.log(`performance trace: ${this.results[i].name} ${this.results[i].dur.toFixed(3)}`); | ||
| } |
There was a problem hiding this comment.
| for (let i = 0; i < 20 && i < this.results.length; i++) { | |
| // eslint-disable-next-line no-console | |
| console.log(`performance trace: ${this.results[i].name} ${this.results[i].dur.toFixed(3)}`); | |
| } | |
| for (const [index, {name, dur}] of this.results.entries()) { | |
| if (index >= 20) break; | |
| console.info(`performance trace: ${name} ${dur.toFixed(3)}`); | |
| } |
There was a problem hiding this comment.
I do not think it is performant, by the for ( let ...; i < len; ...) loop, we do not need to create new "entries" object or extra if check
| if (perfTracer) { | ||
| for (const func of functions) perfTracer.recordCall(func.name, func); | ||
| } else { | ||
| for (const func of functions) func(); | ||
| } |
There was a problem hiding this comment.
| if (perfTracer) { | |
| for (const func of functions) perfTracer.recordCall(func.name, func); | |
| } else { | |
| for (const func of functions) func(); | |
| } | |
| for (const func of functions) { | |
| perfTracer?.recordCall(func.name, func) ?? func(); | |
| } |
There was a problem hiding this comment.
I do not think it is performant.
By using the if, we do not need to check perfTracer anymore in the loop
* giteaofficial/main: Disable `vet` as part of `go test` (go-gitea#33662) Refactor error system (go-gitea#33771) Add migrations and doctor fixes (go-gitea#33556) Refactor mail code (go-gitea#33768) Refactor global init code and add more comments (go-gitea#33755)
Follow up #33748 (refactor a lot and let's forget the old code: https://github.com/go-gitea/gitea/pull/33755/files?diff=split&w=0)
Now there are 3 "global" functions:
.ui.dropdowndata-global-init="initInputAutoFocusEnd"data-global-click="onCommentReactionButtonClick"And introduce
initGlobalInputto replace oldinitAutoFocusEndandattachDirAuto, usedata-global-initto replace fragile.js-autofocus-endselector.Another benefit is that by the new approach, no matter how many times
registerGlobalInitFuncis called, we only need to do one "querySelectorAll" in the last step, it could slightly improve the performance.