Skip to content

WIP: introduce compressedArrayElement for profile data #5012

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions src/components/tooltip/CallNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getStackType } from 'firefox-profiler/profile-logic/transforms';
import { parseFileNameFromSymbolication } from 'firefox-profiler/utils/special-paths';
import { formatCallNodeNumberWithUnit } from 'firefox-profiler/utils/format-numbers';
import { Icon } from 'firefox-profiler/components/shared/Icon';
import { getCategoryPairLabel } from 'firefox-profiler/profile-logic/profile-data';
import { getCategoryPairLabel, compressedArrayElement } from 'firefox-profiler/profile-logic/profile-data';
import { countPositiveValues } from 'firefox-profiler/utils';

import type {
Expand Down Expand Up @@ -366,17 +366,17 @@ export class TooltipCallNode extends React.PureComponent<Props> {
displayStackType,
} = this.props;
const callNodeTable = callNodeInfo.getCallNodeTable();
const categoryIndex = callNodeTable.category[callNodeIndex];
const categoryIndex = compressedArrayElement(callNodeTable.category, callNodeIndex);
const categoryColor = categories[categoryIndex].color;
const subcategoryIndex = callNodeTable.subcategory[callNodeIndex];
const subcategoryIndex = compressedArrayElement(callNodeTable.subcategory,callNodeIndex);
const funcIndex = callNodeTable.func[callNodeIndex];
const innerWindowID = callNodeTable.innerWindowID[callNodeIndex];
const innerWindowID = compressedArrayElement(callNodeTable.innerWindowID, callNodeIndex);
const funcStringIndex = thread.funcTable.name[funcIndex];
const funcName = thread.stringTable.getString(funcStringIndex);

let fileName = null;

const fileNameIndex = thread.funcTable.fileName[funcIndex];
const fileNameIndex = compressedArrayElement(thread.funcTable.fileName, funcIndex);
if (fileNameIndex !== null) {
let fileNameURL = thread.stringTable.getString(fileNameIndex);
// fileNameURL could be a path from symbolication (potentially using "special path"
Expand All @@ -386,10 +386,10 @@ export class TooltipCallNode extends React.PureComponent<Props> {

// JS functions have information about where the function starts.
// Add :<line>:<col> to the URL, if known.
const lineNumber = thread.funcTable.lineNumber[funcIndex];
const lineNumber = compressedArrayElement(thread.funcTable.lineNumber, funcIndex);
if (lineNumber !== null) {
fileNameURL += ':' + lineNumber;
const columnNumber = thread.funcTable.columnNumber[funcIndex];
const columnNumber = compressedArrayElement(thread.funcTable.columnNumber, funcIndex);
if (columnNumber !== null) {
fileNameURL += ':' + columnNumber;
}
Expand Down
45 changes: 30 additions & 15 deletions src/profile-logic/profile-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ export function filterThreadToSearchString(
}

const fileNameIndex = funcTable.fileName[func];
if (fileNameIndex !== null) {
if (fileNameIndex !== null && fileNameIndex !== undefined) {
const fileNameString = stringTable.getString(fileNameIndex);
if (fileNameString.toLowerCase().includes(lowercaseSearchString)) {
return true;
Expand Down Expand Up @@ -2502,14 +2502,14 @@ export function getOriginAnnotationForFunc(
let origin = null;
const resourceIndex = funcTable.resource[funcIndex];
if (resourceIndex !== -1) {
resourceType = resourceTable.type[resourceIndex];
resourceType = compressedArrayElement(resourceTable.type, resourceIndex);
const resourceNameIndex = resourceTable.name[resourceIndex];
origin = stringTable.getString(resourceNameIndex);
}

const fileNameIndex = funcTable.fileName[funcIndex];
let fileName;
if (fileNameIndex !== null) {
if (fileNameIndex !== null && fileNameIndex !== undefined) {
fileName = stringTable.getString(fileNameIndex);

// Strip off any filename decorations from symbolication. It could be a path
Expand All @@ -2518,17 +2518,17 @@ export function getOriginAnnotationForFunc(
// strip it down to just the actual path.
fileName = parseFileNameFromSymbolication(fileName).path;

if (frameLineNumber !== null) {
if (frameLineNumber !== null && frameLineNumber !== undefined) {
fileName += ':' + frameLineNumber;
if (frameColumnNumber !== null) {
if (frameColumnNumber !== null && frameColumnNumber !== undefined) {
fileName += ':' + frameColumnNumber;
}
} else {
const lineNumber = funcTable.lineNumber[funcIndex];
if (lineNumber !== null) {
if (lineNumber !== null && lineNumber !== undefined) {
fileName += ':' + lineNumber;
const columnNumber = funcTable.columnNumber[funcIndex];
if (columnNumber !== null) {
if (columnNumber !== null && columnNumber !== undefined) {
fileName += ':' + columnNumber;
}
}
Expand Down Expand Up @@ -2578,7 +2578,7 @@ export function reserveFunctionsInThread(
resourceIndex < resourceTable.length;
resourceIndex++
) {
const resourceType = resourceTable.type[resourceIndex];
const resourceType = compressedArrayElement(resourceTable.type, resourceIndex);
const name = resourceTable.name[resourceIndex];
const isJS = jsResourceTypes.includes(resourceType);
const fileName = resourceType === resourceTypes.url ? name : null;
Expand Down Expand Up @@ -3443,11 +3443,12 @@ export function findAddressProofForFile(
if (address === null) {
continue;
}
const resource = funcTable.resource[func];
if (resourceTable.type[resource] !== resourceTypes.library) {
const resourceIndex = funcTable.resource[func];
const resourceType = compressedArrayElement(resourceTable.type, resourceIndex);
if (resourceType !== resourceTypes.library) {
continue;
}
const libIndex = resourceTable.lib[resource];
const libIndex = resourceTable.lib[resourceIndex];
if (libIndex === null) {
continue;
}
Expand Down Expand Up @@ -3621,12 +3622,13 @@ export function getBottomBoxInfoForCallNode(

const callNodeTable = callNodeInfo.getCallNodeTable();
const funcIndex = callNodeTable.func[callNodeIndex];
const fileName = funcTable.fileName[funcIndex];
const fileName = compressedTableelement(funcTable.fileName, funcIndex);
const sourceFile = fileName !== null ? stringTable.getString(fileName) : null;
const resource = funcTable.resource[funcIndex];
const resourceIndex = funcTable.resource[funcIndex];
const resourceType = compressedArrayElement(resourceTable.type, resourceIndex);
const libIndex =
resource !== -1 && resourceTable.type[resource] === resourceTypes.library
? resourceTable.lib[resource]
resource !== -1 && resourceType === resourceTypes.library
? compressedArrayElement(resourceTable.lib, resourceIndex)
: null;
const nativeSymbolsForCallNode = getNativeSymbolsForCallNode(
callNodeIndex,
Expand Down Expand Up @@ -3679,3 +3681,16 @@ export function determineTimelineType(profile: Profile): TimelineType {
// Have both category and CPU usage information. Use 'cpu-category'.
return 'cpu-category';
}

/**
* Helper function allow specifying arrays that contain the same element as
* just that element itself, to save space in profile JSON and memory.
*
* e.g.:
* `lineNumber: [0, 0, 0, 0]`
* becomes:
* `lineNumber: 0`
*/
export function compressedArrayElement(array: any, index: number): any {
return Array.isArray(array) ? array[index] : array;
}