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

change Package children to be set of PackageableElement instead of array for performance #965

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 5 additions & 0 deletions .changeset/clean-tools-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@finos/legend-graph': patch
---

Change `Package` children to be set of `PackageableElement` instead of array for performance.
5 changes: 5 additions & 0 deletions .changeset/spicy-rockets-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@finos/legend-query": patch
"@finos/legend-server-depot": patch
"@finos/legend-studio": patch
---
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export enum GRAPH_MANAGER_LOG_EVENT {

GRAPH_BUILDER_SYSTEM_BUILT = 'GRAPH_BUILDER_SYSTEM_BUILT',
GRAPH_BUILDER_DEPENDENCIES_PREPROCESSED = 'GRAPH_BUILDER_DEPENDENCIES_PREPROCESSED',
GRAPH_BUILDER_DEPENDENCIES_ENTITIES_FETCHED = 'GRAPH_BUILDER_DEPENDENCIES_ENTITIES_FETCHED',
GRAPH_BUILDER_DEPENDENCIES_PROCESSED = 'GRAPH_BUILDER_DEPENDENCIES_PROCESSED',
GRAPH_BUILDER_DEPENDENCIES_BUILT = 'GRAPH_BUILDER_DEPENDENCIES_BUILT',
GRAPH_BUILDER_GENERATIONS_BUILT = 'GRAPH_BUILDER_GENERATIONS_BUILT',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
type Hashable,
hashArray,
assertTrue,
addUniqueEntry,
AssertionError,
} from '@finos/legend-shared';
import {
Expand Down Expand Up @@ -58,7 +57,7 @@ export class Package extends PackageableElement implements Hashable {
}

addChild(value: PackageableElement): void {
addUniqueEntry(this.children, value);
this.children.push(value);
}

addElement(element: PackageableElement): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
LogEvent.create(GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_SYSTEM_BUILT),
Date.now() - startTime,
'ms',
`[profile: ${systemModel.ownProfiles.length}, enumeration: ${systemModel.ownEnumerations.length}]`,
`[class: ${systemModel.ownClasses.length}, profile: ${systemModel.ownProfiles.length}, enumeration: ${systemModel.ownEnumerations.length}, [TOTAL]: ${systemModel.allOwnElements.length}]`,
);
}
systemModel.buildState.pass();
Expand All @@ -510,6 +510,18 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
options?: GraphBuilderOptions,
): GeneratorFn<void> {
const startTime = Date.now();
if (!options?.quiet) {
this.log.info(
LogEvent.create(
GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_DEPENDENCIES_ENTITIES_FETCHED,
),
Date.now() - startTime,
'ms',
`[projects: ${dependencyEntitiesMap.size}, entities: ${
Array.from(dependencyEntitiesMap.values()).flat().length
}]`,
);
}
dependencyManager.buildState.reset();
// Create a dummy graph for system processing. This is to ensure dependency models do not depend on the main graph
const graph = new PureModel(
Expand Down Expand Up @@ -595,6 +607,18 @@ export class V1_PureGraphManager extends AbstractPureGraphManager {
Date.now() - startTime,
'ms',
);
this.log.info(
LogEvent.create(
GRAPH_MANAGER_LOG_EVENT.GRAPH_BUILDER_DEPENDENCIES_BUILT,
),
Date.now() - startTime,
'ms',
`[elements: ${
Array.from(dependencyManager.projectDependencyModelsIndex.values())
.map((v) => v.allOwnElements)
.flat().length
}]`,
);
}
} catch (error) {
assertErrorThrown(error);
Expand Down
28 changes: 24 additions & 4 deletions packages/legend-query/src/stores/LegendQueryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import {
import type { LegendQueryPluginManager } from '../application/LegendQueryPluginManager';
import type { LegendQueryConfig } from '../application/LegendQueryConfig';
import { LegendQueryEventNotifierService } from './LegendQueryEventNotifierService';
import { DEPOT_SERVER_LOG_EVENT } from '@finos/legend-server-depot/src/DepotServerClient';

export abstract class QueryInfoState {
queryStore: LegendQueryStore;
Expand Down Expand Up @@ -716,11 +717,15 @@ export class LegendQueryStore {
}
}

*buildGraph(project: ProjectData, versionId: string): GeneratorFn<void> {
*buildGraph(
project: ProjectData,
versionId: string,
options?: { quiet?: boolean },
): GeneratorFn<void> {
try {
this.buildGraphState.inProgress();
let entities: Entity[] = [];

const startTime = Date.now();
if (versionId === SNAPSHOT_VERSION_ALIAS) {
entities = (yield this.depotServerClient.getLatestRevisionEntities(
project.groupId,
Expand All @@ -735,7 +740,13 @@ export class LegendQueryStore {
: versionId,
)) as Entity[];
}

if (!options?.quiet) {
this.graphManagerState.graphManager.log.info(
LogEvent.create(DEPOT_SERVER_LOG_EVENT.DEPENDENCY_ENTITIES_FETCH),
Date.now() - startTime,
'ms',
);
}
this.graphManagerState.resetGraph();
// build dependencies
const dependencyManager =
Expand All @@ -746,7 +757,7 @@ export class LegendQueryStore {
this.graphManagerState.systemModel,
dependencyManager,
(yield flowResult(
this.getProjectDependencyEntities(project, versionId),
this.getProjectDependencyEntities(project, versionId, options),
)) as Map<string, Entity[]>,
),
);
Expand Down Expand Up @@ -774,10 +785,12 @@ export class LegendQueryStore {
*getProjectDependencyEntities(
project: ProjectData,
versionId: string,
options?: { quiet?: boolean },
): GeneratorFn<Map<string, Entity[]>> {
this.buildGraphState.inProgress();
const dependencyEntitiesMap = new Map<string, Entity[]>();
try {
const startTime = Date.now();
let dependencyEntitiesJson: PlainObject<ProjectVersionEntities>[] = [];
if (versionId === SNAPSHOT_VERSION_ALIAS) {
dependencyEntitiesJson =
Expand All @@ -799,6 +812,13 @@ export class LegendQueryStore {
false,
)) as PlainObject<ProjectVersionEntities>[];
}
if (!options?.quiet) {
this.graphManagerState.graphManager.log.info(
LogEvent.create(DEPOT_SERVER_LOG_EVENT.DEPENDENCY_ENTITIES_FETCH),
Date.now() - startTime,
'ms',
);
}
dependencyEntitiesJson
.map((e) => ProjectVersionEntities.serialization.fromJson(e))
.forEach((dependencyInfo) => {
Expand Down
4 changes: 4 additions & 0 deletions packages/legend-server-depot/src/DepotServerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export interface DepotServerClientConfig {
TEMPORARY__useLegacyDepotServerAPIRoutes?: boolean | undefined;
}

export enum DEPOT_SERVER_LOG_EVENT {
DEPENDENCY_ENTITIES_FETCH = 'DEPENDENCY_ENTITIES_FETCH',
}

export class DepotServerClient extends AbstractServerClient {
private TEMPORARY__useLegacyDepotServerAPIRoutes = false;

Expand Down
2 changes: 1 addition & 1 deletion packages/legend-server-depot/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export * from './models/ProjectVersionEntities';
export { StoredEntity } from './models/StoredEntity';
export { DepotScope } from './models/DepotScope';

export { DepotServerClient } from './DepotServerClient';
export { DepotServerClient, DEPOT_SERVER_LOG_EVENT } from './DepotServerClient';
export * from './DepotServerClientProvider';

export * from './DepotServerClientTestUtils';
Expand Down
15 changes: 12 additions & 3 deletions packages/legend-studio/src/stores/EditorGraphState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
ProjectData,
ProjectDependencyCoordinates,
generateGAVCoordinates,
DEPOT_SERVER_LOG_EVENT,
} from '@finos/legend-server-depot';
import {
type SetImplementation,
Expand Down Expand Up @@ -960,9 +961,9 @@ export class EditorGraphState {
}
}

*getConfigurationProjectDependencyEntities(): GeneratorFn<
Map<string, Entity[]>
> {
*getConfigurationProjectDependencyEntities(options?: {
quiet?: boolean;
}): GeneratorFn<Map<string, Entity[]>> {
const dependencyEntitiesMap = new Map<string, Entity[]>();
const currentConfiguration =
this.editorStore.projectConfigurationEditorState
Expand All @@ -974,6 +975,7 @@ export class EditorGraphState {
currentConfiguration.projectDependencies,
),
)) as ProjectDependencyCoordinates[];
const startTime = Date.now();
// NOTE: if A@v1 is transitive dependencies of 2 or more
// direct dependencies, metadata server will take care of deduplication
const dependencyEntitiesJson =
Expand All @@ -984,6 +986,13 @@ export class EditorGraphState {
true,
true,
)) as PlainObject<ProjectVersionEntities>[];
if (!options?.quiet) {
this.editorStore.applicationStore.log.info(
LogEvent.create(DEPOT_SERVER_LOG_EVENT.DEPENDENCY_ENTITIES_FETCH),
Date.now() - startTime,
'ms',
);
}
const dependencyEntities = dependencyEntitiesJson.map((e) =>
ProjectVersionEntities.serialization.fromJson(e),
);
Expand Down