-
Notifications
You must be signed in to change notification settings - Fork 532
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
Prefetch snapshot so as to avoid network call from critical path. #5968
Merged
Merged
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e73bb63
Prefetch snapshot to avoid it from critical path
jatgarg d5a2670
merge conflict
jatgarg 8591df5
add to export
jatgarg 7ee7cde
Pr sugg
jatgarg 13e5e41
Pr sugg
jatgarg fa5bb33
Pr sugg
jatgarg cb4ed95
Pr sugg
jatgarg ae3a8ba
Pr sugg
jatgarg 6d4120a
Pr sugg
jatgarg 2cd228d
Pr sugg
jatgarg a5b2a28
bundle size testr
jatgarg a94c097
bundle size test
jatgarg bb9eea5
Merge branch 'main' of https://github.com/microsoft/FluidFramework in…
jatgarg b44e4c4
add api report
jatgarg 9c1052b
remove spaces
jatgarg 024bfa7
Add support to test it with webpack fluid laoder
jatgarg 296c388
don't import odsp cache
jatgarg 2df4150
cache
jatgarg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import { ITelemetryLogger } from "@fluidframework/common-definitions"; | ||
import { fetchTokenErrorCode, throwOdspNetworkError } from "@fluidframework/odsp-doclib-utils"; | ||
import { | ||
IOdspResolvedUrl, | ||
isTokenFromCache, | ||
OdspResourceTokenFetchOptions, | ||
TokenFetcher, | ||
TokenFetchOptions, | ||
tokenFromResponse, | ||
} from "@fluidframework/odsp-driver-definitions"; | ||
import { PerformanceEvent } from "@fluidframework/telemetry-utils"; | ||
import { IOdspSnapshot } from "./contracts"; | ||
|
||
export function evalBlobsAndTrees(snapshot: IOdspSnapshot) { | ||
let numTrees = 0; | ||
let numBlobs = 0; | ||
let encodedBlobsSize = 0; | ||
let decodedBlobsSize = 0; | ||
for (const tree of snapshot.trees) { | ||
for(const treeEntry of tree.entries) { | ||
jatgarg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (treeEntry.type === "blob") { | ||
numBlobs++; | ||
} else if (treeEntry.type === "tree") { | ||
numTrees++; | ||
} | ||
} | ||
} | ||
if (snapshot.blobs !== undefined) { | ||
for (const blob of snapshot.blobs) { | ||
decodedBlobsSize += blob.size; | ||
encodedBlobsSize += blob.content.length; | ||
} | ||
} | ||
return { numTrees, numBlobs, encodedBlobsSize, decodedBlobsSize }; | ||
} | ||
|
||
export function toInstrumentedOdspTokenFetcher( | ||
logger: ITelemetryLogger, | ||
resolvedUrl: IOdspResolvedUrl, | ||
tokenFetcher: TokenFetcher<OdspResourceTokenFetchOptions>, | ||
throwOnNullToken: boolean, | ||
): (options: TokenFetchOptions, name: string) => Promise<string | null> { | ||
return async (options: TokenFetchOptions, name: string) => { | ||
// Telemetry note: if options.refresh is true, there is a potential perf issue: | ||
// Host should optimize and provide non-expired tokens on all critical paths. | ||
// Exceptions: race conditions around expiration, revoked tokens, host that does not care | ||
// (fluid-fetcher) | ||
return PerformanceEvent.timedExecAsync( | ||
logger, | ||
{ | ||
eventName: `${name}_GetToken`, | ||
attempts: options.refresh ? 2 : 1, | ||
hasClaims: !!options.claims, | ||
hasTenantId: !!options.tenantId, | ||
}, | ||
async (event) => tokenFetcher({ | ||
...options, | ||
siteUrl: resolvedUrl.siteUrl, | ||
driveId: resolvedUrl.driveId, | ||
itemId: resolvedUrl.itemId, | ||
}).then((tokenResponse) => { | ||
const token = tokenFromResponse(tokenResponse); | ||
// This event alone generates so many events that is materially impacts cost of telemetry | ||
// Thus do not report end event when it comes back quickly. | ||
// Note that most of the hosts do not report if result is comming from cache or not, | ||
// so we can't rely on that here | ||
if (event.duration >= 32) { | ||
event.end({ fromCache: isTokenFromCache(tokenResponse), isNull: token === null }); | ||
} | ||
if (token === null && throwOnNullToken) { | ||
throwOdspNetworkError(`${name} Token is null`, fetchTokenErrorCode); | ||
} | ||
return token; | ||
}), | ||
{ cancel: "generic" }); | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Rather than an
odspUtils2.ts
, what about just creating two separate files:evalBlobsAndTrees.ts
andtoInstrementedOdspTokenFetcher.ts
?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.
Actually I added these to odsputils only because we already import a lot from that file. So no need to add these in a separate file.