perf: import some modules dynamically #3179
No reviewers
Labels
No Label
area/internal-code
changes requested
confirmed
dependencies
duplicate
good first issue
help wanted
hosting
invalid
kind/bug
kind/feature
question
wontfix
No Milestone
No project
No Assignees
4 Participants
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: vikunja/frontend#3179
Loading…
Reference in New Issue
No description provided.
Delete Branch "WofWca/frontend:dynamic-import"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi WofWca!
Thank you for creating a PR!
I've deployed the changes of this PR on a preview environment under this URL: https://3179-dynamic-import--vikunja-frontend-preview.netlify.app
You can use this url to view the changes live and test them out.
You will need to manually connect this to an api running somehwere. The easiest to use is https://try.vikunja.io/.
Have a nice day!
Hi @WofWca,
good idea to load some modules dynamically. Did you do some performance testing before you changed these imports? In general I'm a big fan of loading unnecessary stuff later. In this case these modules don't seem to be that large, meaning the performance gain might be minor.
Nope, I didn't do any tests.
I'm just hoping to start a mainstream.
@ -35,8 +35,6 @@ import NoAuthWrapper from '@/components/misc/no-auth-wrapper.vue'
import Ready from '@/components/misc/ready.vue'
import {setLanguage} from '@/i18n'
import AccountDeleteService from '@/services/accountDelete'
Independent from my other comment:
We try to collect all imports in the beginning of the file even if they are dynamic.
This makes it easier to switch between a normal and a dynamic import.
You can find an example of this in the router.
Please see if the new change is ok.
@ -44,6 +42,9 @@ import {useBaseStore} from '@/stores/base'
import {useColorScheme} from '@/composables/useColorScheme'
import {useBodyClass} from '@/composables/useBodyClass'
const importAccountDeleteService = async () => (await import('@/services/accountDelete')).default
You can remove the
async
andawait
part to make this a bit simpler.If you return a promise in a function it will automatically be awaitable / thenable.
Where do I access
.default
then? Below, where it's used?Ok good point.
What about abstracting this? Then we could also add a try catch block which would make sense the moment it's async.
I think this makes sense, since it's all just about putting the imports at the top.
I don't think it's worth it. Default is not always the only used import.
How about something like
safeImport
andsafeImportDefault
(wrappingsafeImport
).Vues components are always default exports and many other files use default exports in this project.
What would be in the catch block? What should be returned if the fetch fails? Or are you talking about returning a
Result
type, like in Rust?I don't write Rust but I heard that the
Result
type is really nice.Originally I thought it might make sense to show a message to the user.
But we already have a block to handle unhandled rejections—currently only active in dev mode though.
What do you think would make most sense?
Non-execution flow breaking error handling is nice, but I don't think it's just about this MR, e.g. the function could also throw at
accountDeletionService.confirm(
. I would search the internet for what people have come up with, there are some nice APIs out there I'm sure.Also it'd be nice to first figure out what we want to happen in case something fails before we write the code.
@ -64,8 +65,11 @@ watch(accountDeletionConfirm, async (accountDeletionConfirm) => {
return
}
const successP = importSuccess()
Why don't you await here?
Because it would pause the execution of the rest of the function.
I just realised that we already load the messages in
main.ts
.Taking this into consideration this pull request only dynamically imports
accountDelete.ts
.Since this pull request adds an additional request at the same time I would prefer not to merge this and instead solve the core issue.
@konrad Any thoughts?
Does it? I think the build script should be smart enough to not include the same module twice.
Then we could maybe add dynamic import there as well at some point. Or maybe not.
If it doesn't split the import in another file what's the use for the dynamic import (seriously interested)?
Runtime-wise there's no point. It's just so that it does get split if we get rid of the other static imports.
What's the core issue?
From what I understood, the account deletion service would only be loaded when it really is required? That sounds like a good idea to me. The effect is really minor though but I guess it still doesn't hurt?
Hey @WofWca do you still want to continue with this?
Hi!
What does it take? I see CI failed. If I resolve it, would you merge the MR?
Please rebase to the latest changes, if the CI passes this should be fine to merge.
Ok, I'll get around to this within a week 👌
4f57aa6b87
to7a3555a48c
Guess it worked?
Thanks!