-
Notifications
You must be signed in to change notification settings - Fork 2
react-native: reduce breadcrumb size #320
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
Merged
perf2711
merged 7 commits into
main
from
feature/BT-718-reduce-breadcrumb-size--react-native-2
Nov 22, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
71843f8
react-native: add factory to FileBreadcrumbsStorage and use it
perf2711 4815b71
react-native: add lengthChunkSplitter
perf2711 e5fb317
react-native: add combinedChunkSplitter, use both splitters in FileBr…
perf2711 54a854c
react-native: add FileBreadcrumbsStorage tests
perf2711 63b7d64
react-native: fix maximumTotalBreadcrumbsSize allowing 2x size
perf2711 281651e
react-native: add tests for breadcrumbs with lines in them (NFC)
perf2711 5ff1447
react-native: update test case in FileBreadcrumbsStorage.spec (NFC)
perf2711 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 hidden or 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 hidden or 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 hidden or 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
33 changes: 33 additions & 0 deletions
33
packages/react-native/src/storage/combinedChunkSplitter.ts
This file contains hidden or 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,33 @@ | ||
import type { Chunk, ChunkSplitter } from './Chunkifier'; | ||
|
||
/** | ||
* Combines several splitters into one. | ||
* | ||
* Each splitter is checked, in order that they are passed. | ||
* Splitters receive always the first chunk. | ||
* | ||
* If more than one splitter returns splitted chunks, the second | ||
* chunks are concatenated and treated as one chunk. | ||
* @param splitters | ||
* @returns | ||
*/ | ||
export function combinedChunkSplitter<W extends Chunk>( | ||
join: (chunks: W[]) => W, | ||
...splitters: ChunkSplitter<W>[] | ||
): ChunkSplitter<W> { | ||
return (chunk) => { | ||
const rest: W[] = []; | ||
|
||
for (const splitter of splitters) { | ||
const [c1, c2] = splitter(chunk); | ||
chunk = c1; | ||
if (c2) { | ||
// Prepend second chunk to the rest | ||
rest.unshift(c2); | ||
} | ||
} | ||
|
||
// If any chunks are in rest, concatenate them and pass as the second chunk | ||
return [chunk, rest.length ? join(rest) : undefined]; | ||
}; | ||
} |
This file contains hidden or 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,57 @@ | ||
import type { ChunkSplitter } from './Chunkifier'; | ||
|
||
/** | ||
* Splits data into chunks with maximum length. | ||
* @param maxLength Maximum length of one chunk. | ||
* @param wholeLines Can be one of: | ||
* * `"skip"` - if last line does not fit in the chunk, it will be skipped entirely | ||
* * `"break"` - if last line does not fit in the chunk, it will be broken into two new chunks | ||
* * `false` - last line will be always broken into old and new chunk | ||
*/ | ||
export function lengthChunkSplitter( | ||
maxLength: number, | ||
wholeLines: 'skip' | 'break' | false = false, | ||
): ChunkSplitter<string> { | ||
let seen = 0; | ||
|
||
const emptyBuffer = ''; | ||
|
||
return function lengthChunkSplitter(data) { | ||
const remainingLength = maxLength - seen; | ||
if (data.length <= remainingLength) { | ||
seen += data.length; | ||
return [data]; | ||
} | ||
|
||
seen = 0; | ||
if (!wholeLines) { | ||
return [data.substring(0, remainingLength), data.substring(remainingLength)]; | ||
} | ||
|
||
// Check last newline before first chunk end | ||
const lastLineIndex = data.substring(0, remainingLength).lastIndexOf('\n'); | ||
|
||
// If there is no newline, pass empty buffer as the first chunk | ||
// and write all data into the second | ||
if (lastLineIndex === -1) { | ||
if (remainingLength !== maxLength) { | ||
return [emptyBuffer, data]; | ||
} | ||
|
||
if (wholeLines === 'break') { | ||
// Break the line into two chunks | ||
return [data.substring(0, remainingLength), data.substring(remainingLength)]; | ||
} else { | ||
const firstNewLine = data.indexOf('\n', remainingLength); | ||
if (firstNewLine === -1) { | ||
return [emptyBuffer]; | ||
} | ||
|
||
return [emptyBuffer, data.substring(firstNewLine + 1)]; | ||
} | ||
} | ||
|
||
// +1 - include trailing newline in first chunk, skip in second | ||
return [data.substring(0, lastLineIndex + 1), data.substring(lastLineIndex + 1)]; | ||
}; | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.