Skip to content

Commit a44acf1

Browse files
authored
Remove SharedArrayBuffer workaround (#5596)
[Production](https://profiler.firefox.com/public/283zgs51v5kc3yxtjkm5w2x249468x99ydds610/flame-graph/?globalTrackOrder=1w46705&hiddenGlobalTracks=5&hiddenLocalTracksByPid=5472-0wAiAkwBhBjwE6E8wEhEjwFiFkwHv~5511-0wyp~5607-0wxhxjwCj~5696-0wxj~5855-0wCbCdwDi~6253-0whkwy4&localTrackOrderByPid=5472-HnwHpHbBaBcBnBpAnEhEfEgBlC8FeDqBkEqD7E5CjCkghy6z7zdA1EaA2A3E3EvF0FlF1FnF2FoG3G4FpG5GbGcG7GdGfGgGeGhwGoGuGpwGtGvH2H0H1H3H4HhwHmAuEuFawFcH7HvCtAgDcAoAsAtC7ClCsDsHrHsE0CuBgAbwAeAvB0B2wB4B6wB9BbBdBoBqwC2ErEtAiE9ElEmEoEjHfHgA7wAaF3F4jkA5A6DrDtDuAjAkF5wF9FvwG2AlAqB1G8EeHdC3FdC5DeDfEcE1E7ArBjEsHqHcAfCqCpCiDpC9DgCawChDhwDoBhAhilwy5y7wz6z8wzczewA0HaE2C4FkBeG9HtEdA4BfDdHeEpBmE6FfwFiFqwFtGaEkH9FmG6H8EbEnD8wDaC6CvwD6f0weBiFjFuApCrAmE8EiDvE4B5CmCnHuCoDbH5H6~6253-8mursewgy0wy2cdapx3x1n9txhwxm7x4hx5bx06oxewxgqx6wxd3w5021vliwkxnwxvy4x2y3~5855-D5DhCrC9Cagwimwox0wx8xbxcxexdxfwxhxjwxlxpwy1y4wybydwyuz0wz2z6wz8zcwzkzqwAnApwBoC6wC8CuD2CvD0DbwDdCqqCbD9Day2y3ycD1krx9xaxiz3wz5znwzpDfD7DiD6zlzmAoC2BpwC1yvjlpD4DeCsD8swvxmwxoz9wzbD3dwf0w4b5wacCtDgCpC5C3C4CdCgwCeChCjwClCiCmwCoCc&thread=Kv&v=11) | [Main branch](https://main--perf-html.netlify.app/public/283zgs51v5kc3yxtjkm5w2x249468x99ydds610/flame-graph/?globalTrackOrder=1w46705&hiddenGlobalTracks=5&hiddenLocalTracksByPid=5472-0wAiAkwBhBjwE6E8wEhEjwFiFkwHv~5511-0wyp~5607-0wxhxjwCj~5696-0wxj~5855-0wCbCdwDi~6253-0whkwy4&localTrackOrderByPid=5472-HnwHpHbBaBcBnBpAnEhEfEgBlC8FeDqBkEqD7E5CjCkghy6z7zdA1EaA2A3E3EvF0FlF1FnF2FoG3G4FpG5GbGcG7GdGfGgGeGhwGoGuGpwGtGvH2H0H1H3H4HhwHmAuEuFawFcH7HvCtAgDcAoAsAtC7ClCsDsHrHsE0CuBgAbwAeAvB0B2wB4B6wB9BbBdBoBqwC2ErEtAiE9ElEmEoEjHfHgA7wAaF3F4jkA5A6DrDtDuAjAkF5wF9FvwG2AlAqB1G8EeHdC3FdC5DeDfEcE1E7ArBjEsHqHcAfCqCpCiDpC9DgCawChDhwDoBhAhilwy5y7wz6z8wzczewA0HaE2C4FkBeG9HtEdA4BfDdHeEpBmE6FfwFiFqwFtGaEkH9FmG6H8EbEnD8wDaC6CvwD6f0weBiFjFuApCrAmE8EiDvE4B5CmCnHuCoDbH5H6~6253-8mursewgy0wy2cdapx3x1n9txhwxm7x4hx5bx06oxewxgqx6wxd3w5021vliwkxnwxvy4x2y3~5855-D5DhCrC9Cagwimwox0wx8xbxcxexdxfwxhxjwxlxpwy1y4wybydwyuz0wz2z6wz8zcwzkzqwAnApwBoC6wC8CuD2CvD0DbwDdCqqCbD9Day2y3ycD1krx9xaxiz3wz5znwzpDfD7DiD6zlzmAoC2BpwC1yvjlpD4DeCsD8swvxmwxoz9wzbD3dwf0w4b5wacCtDgCpC5C3C4CdCgwCeChCjwClCiCmwCoCc&thread=Kv&v=11) | [Deploy preview](https://deploy-preview-5596--perf-html.netlify.app/public/283zgs51v5kc3yxtjkm5w2x249468x99ydds610/flame-graph/?globalTrackOrder=1w46705&hiddenGlobalTracks=5&hiddenLocalTracksByPid=5472-0wAiAkwBhBjwE6E8wEhEjwFiFkwHv~5511-0wyp~5607-0wxhxjwCj~5696-0wxj~5855-0wCbCdwDi~6253-0whkwy4&localTrackOrderByPid=5472-HnwHpHbBaBcBnBpAnEhEfEgBlC8FeDqBkEqD7E5CjCkghy6z7zdA1EaA2A3E3EvF0FlF1FnF2FoG3G4FpG5GbGcG7GdGfGgGeGhwGoGuGpwGtGvH2H0H1H3H4HhwHmAuEuFawFcH7HvCtAgDcAoAsAtC7ClCsDsHrHsE0CuBgAbwAeAvB0B2wB4B6wB9BbBdBoBqwC2ErEtAiE9ElEmEoEjHfHgA7wAaF3F4jkA5A6DrDtDuAjAkF5wF9FvwG2AlAqB1G8EeHdC3FdC5DeDfEcE1E7ArBjEsHqHcAfCqCpCiDpC9DgCawChDhwDoBhAhilwy5y7wz6z8wzczewA0HaE2C4FkBeG9HtEdA4BfDdHeEpBmE6FfwFiFqwFtGaEkH9FmG6H8EbEnD8wDaC6CvwD6f0weBiFjFuApCrAmE8EiDvE4B5CmCnHuCoDbH5H6~6253-8mursewgy0wy2cdapx3x1n9txhwxm7x4hx5bx06oxewxgqx6wxd3w5021vliwkxnwxvy4x2y3~5855-D5DhCrC9Cagwimwox0wx8xbxcxexdxfwxhxjwxlxpwy1y4wybydwyuz0wz2z6wz8zcwzkzqwAnApwBoC6wC8CuD2CvD0DbwDdCqqCbD9Day2y3ycD1krx9xaxiz3wz5znwzpDfD7DiD6zlzmAoC2BpwC1yvjlpD4DeCsD8swvxmwxoz9wzbD3dwf0w4b5wacCtDgCpC5C3C4CdCgwCeChCjwClCiCmwCoCc&thread=Kv&v=11) `instanceof SharedArrayBuffer` throws if `window.crossOriginIsolated` is false (would need COOP and COEP) This fixes a regression from #5584.
2 parents c405844 + 2a361e2 commit a44acf1

File tree

4 files changed

+7
-21
lines changed

4 files changed

+7
-21
lines changed

src/actions/receive-profile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ async function _extractZipFromResponse(
10651065
async function _extractJsonFromArrayBuffer(
10661066
arrayBuffer: ArrayBuffer
10671067
): Promise<unknown> {
1068-
let profileBytes: Uint8Array<ArrayBufferLike> = new Uint8Array(arrayBuffer);
1068+
let profileBytes = new Uint8Array(arrayBuffer);
10691069
// Check for the gzip magic number in the header.
10701070
if (isGzip(profileBytes)) {
10711071
profileBytes = await decompress(profileBytes);

src/profile-logic/process-profile.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,9 +1980,7 @@ export async function unserializeProfileOfArbitraryFormat(
19801980
// object is constructed from an ArrayBuffer in a different context... which
19811981
// happens in our tests.
19821982
if (String(arbitraryFormat) === '[object ArrayBuffer]') {
1983-
// Obviously Flow doesn't understand that this is correct, so let's help
1984-
// Flow here.
1985-
let arrayBuffer: ArrayBufferLike = arbitraryFormat as any;
1983+
let arrayBuffer = arbitraryFormat as ArrayBuffer;
19861984

19871985
// Check for the gzip magic number in the header. If we find it, decompress
19881986
// the data first.

src/test/store/receive-profile.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('actions/receive-profile', function () {
131131
return states;
132132
}
133133

134-
function encode(string: string): Uint8Array {
134+
function encode(string: string): Uint8Array<ArrayBuffer> {
135135
return new TextEncoder().encode(string);
136136
}
137137

src/utils/gz.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,8 @@ async function readableStreamToBuffer(
3232
return result;
3333
}
3434

35-
// The Streams API doesn't support SAB, and so we need to copy from these to
36-
// use these API's.
37-
function copyBufferIfShared(buffer: Uint8Array): Uint8Array<ArrayBuffer> {
38-
// Check if the buffer is a view into a larger ArrayBuffer (shared)
39-
if (buffer.buffer instanceof SharedArrayBuffer) {
40-
// Create a new buffer with its own ArrayBuffer
41-
return new Uint8Array(buffer);
42-
}
43-
// Return the original buffer if it's not shared
44-
return buffer as Uint8Array<ArrayBuffer>;
45-
}
46-
4735
export async function compress(
48-
data: string | Uint8Array
36+
data: string | Uint8Array<ArrayBuffer>
4937
): Promise<Uint8Array<ArrayBuffer>> {
5038
// Encode the data if it's a string
5139
const arrayData =
@@ -56,22 +44,22 @@ export async function compress(
5644

5745
// Write the data to the compression stream
5846
const writer = compressionStream.writable.getWriter();
59-
writer.write(copyBufferIfShared(arrayData));
47+
writer.write(arrayData);
6048
writer.close();
6149

6250
// Read the compressed data back into a buffer
6351
return readableStreamToBuffer(compressionStream.readable);
6452
}
6553

6654
export async function decompress(
67-
data: Uint8Array
55+
data: Uint8Array<ArrayBuffer>
6856
): Promise<Uint8Array<ArrayBuffer>> {
6957
// Create a gzip compression stream
7058
const decompressionStream = new DecompressionStream('gzip');
7159

7260
// Write the data to the compression stream
7361
const writer = decompressionStream.writable.getWriter();
74-
writer.write(copyBufferIfShared(data));
62+
writer.write(data);
7563
writer.close();
7664

7765
// Read the compressed data back into a buffer

0 commit comments

Comments
 (0)