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

Memoize extension resource loading #341

Merged
merged 1 commit into from
Feb 8, 2024
Merged
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
7 changes: 4 additions & 3 deletions src/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { IExtensionWithExtHostKind, ExtensionServiceOverride } from './service-o
import { CustomSchemas, registerExtensionFile } from './service-override/files'
import { getService } from './services'
import { ExtensionManifestTranslator } from './tools/l10n'
import { throttle } from './tools'
import { throttle, memoized } from './tools'
import { setDefaultApi } from './extension.api'

export type ApiFactory = (extensionId?: string) => Promise<typeof vscode>
Expand Down Expand Up @@ -56,7 +56,8 @@ interface RegisterLocalProcessExtensionResult extends RegisterLocalExtensionResu
function registerExtensionFileUrl (extensionLocation: URI, filePath: string, url: string, mimeType?: string): IDisposable {
const fileDisposable = new DisposableStore()
fileDisposable.add(FileAccess.registerStaticBrowserUri(joinPath(extensionLocation, filePath), URI.parse(url)))
fileDisposable.add(registerExtensionFile(extensionLocation, filePath, async () => {

fileDisposable.add(registerExtensionFile(extensionLocation, filePath, memoized(async () => {
const response = await fetch(url, {
headers: mimeType != null
? {
Expand All @@ -68,7 +69,7 @@ function registerExtensionFileUrl (extensionLocation: URI, filePath: string, url
throw new Error(response.statusText)
}
return new Uint8Array(await response.arrayBuffer())
}))
})))
return fileDisposable
}

Expand Down
Loading