Repository navigation
Conversation
a7252ab to
2670b32
Compare
d2e4f89 to
398852d
Compare
398852d to
8dcc6d2
Compare
zarend
left a comment
There was a problem hiding this comment.
A few questions, but overall this looks good, and will be very helpful for debugging perf issues.
There was a problem hiding this comment.
@alxhub do you know what directory these json files will go in? I'm wondering if they with be "git ignored" or not for apps generated with the CLI.
There was a problem hiding this comment.
This is the Bazel ng_module rule definition, so it only applies to builds done using Bazel (so not the CLI).
They're emitted into blaze-bin along with all other build artifacts, so they're under the .gitignore rules for all build outputs.
There was a problem hiding this comment.
👍 this is a conventional way to do analytics in general. Many many analytics apps or APIs model analytics as events which are string-number pairs (or maybe enums instead of strings).
If we want to really make this interface future-proof, we can add an option to make events enum-string pairs because sometimes it's helpful to record additional metadata when an event happens. I do not think we have a use case for this right now, which is why this is not a blocker for me.
This is something to consider so we can make this perf engine something that we can grow into. If we have both eventCount, and eventLabel, then we can do pretty much anything with this perf system engine.
/**
* Record that a specific event has occurred, possibly more than once.
*/
eventCount(event: PerfNumericalEvent, incrementBy?: number): void;
/**
* Record that a specific event has occurred, and assign a string label to that event.
*/
eventLabel(event: PerfCategoricalEvent, label?: string): void;
// events that we take the total count of over time
enum PerfIncrementalEvent {
// ...
}
// events that that map to the string labels that we record at each occurrence of the event
enum PerfCategoricalEvent {
// ...
}
There was a problem hiding this comment.
The general concept here is that these are counters, which track the occurrences of an event (e.g. "processed a .d.ts input"). We don't currently track when that thing happens, or differentiate between different occurrences in any way.
This is done so that the output is fixed size (a predefined number of counter buckets) and is efficient (no allocation required to track an event which may happen hundreds or thousands of times).
We might decide to have a special logging operation to track certain infrequent events along with the actual timestamp at which they've occurred, plus additional metadata potentially, but right now there isn't a use case for this.
There was a problem hiding this comment.
👍 this is an efficient way to do this.
dgp1130
left a comment
There was a problem hiding this comment.
Already discussed most of this offline.
For future reference, I did suggest using an output group, but this was fiddly to implement and the Bazel flag is protection enough to avoid external users depending on the perf files and seeing non-deterministic outputs.
This does mean that the compiler action will output a non-deterministic file as a side effect, but this is impractical to depend upon and we don't have any more actions to run, so this isn't an issue for now. If this becomes more complex in the future, we might want to consider changing this to an output group.
There was a problem hiding this comment.
Skylib does provide some useful primitives for flags: https://github.com/bazelbuild/bazel-skylib/blob/2b38b2f8bd4b8603d610cfc651fcbb299498147f/rules/common_settings.bzl.
We could use a bool_flag() here and drop the provider, but it seems like we don't have Skylib directly included in the workspace right now (I'm sure we depend on it transitively).
I'm fine doing this with a direct provider, but just wanted to mention the Skylib option to simplify this if we're willing to depend on that directly.
There was a problem hiding this comment.
Yeah, I saw some references to Skylib, but it didn't seem to be something we imported from, and setting something like that up is beyond my knowledge :)
There was a problem hiding this comment.
Maybe this flag should be defined in packages/bazel/BUILD.bazel? No need for it to be at the root package.
There was a problem hiding this comment.
I moved it to //packages/compiler-cli:ng_perf since it's conceptually a configuration option for the compiler.
dgp1130
left a comment
There was a problem hiding this comment.
Couple more things that just randomly came to mind.
8dcc6d2 to
7cd0ea9
Compare
There was a problem hiding this comment.
please note that all of these changes will need to be reimplemented in g3 because it uses forked version of this code.
There was a problem hiding this comment.
Yep - we should be able to reuse the same mechanism in g3.
There was a problem hiding this comment.
interesting, I was going to suggest that you use this try/finally pattern throughout, I wonder why you decided to use it here and not elsewhere.
I suggest that you consider using this pattern everywhere, or even better - use it in combination with a wrapper function:
this.compiler.perfRecorder.phase(PerfPhase.LsReferencesAndRenames, () => {
const templateInfo = getTemplateInfoAtPosition(filePath, position, this.compiler);
if (templateInfo === undefined) {
return this.getReferencesAtTypescriptPosition(filePath, position);
}
return this.getReferencesAtTemplatePosition(templateInfo, position);
});
and internally within phase use try/finally. The overhead of this should be negligible with today's V8, and in return you can automatically restore previous phase and prevent issues with accidentally missing phase end calls.
There was a problem hiding this comment.
I considered that kind of an API, but I originally decided against it for a couple reasons:
- It adds overhead, although as you mention in v8 it's really not that much.
- It complicates debugging by introducing an additional callback to step through. This is a large part of why we prefer
for..ofloops instead of.forEachin the compiler. - It increases the indentation of functions which use it, and may obscure the actual code being run.
- It can interfere with features like type narrowing, since type assertions that happen within the callback don't apply after it returns. There is no way to tell TypeScript "this function will synchronously execute its callback, so any narrowing that happens within the callback should apply after the call as well".
That said, I modified the API to add a .inPhase() operation which works the way you suggest, and it turned out to be fairly clean and readable in most of the situations that tracked a phase. I also like the explicitness of "this chunk of code is considered to be in the given phase" - it makes it easier to reason about where time is going. I think for that reason, we'll go with that API despite the debugging/nesting complications.
There was a problem hiding this comment.
sounds good. I do agree that the code is much more readable with inPhase. Did you intentionally keep some of the phase callsites in the PR because those parts of the code base are more sensitive to the downsides you listed above? Or is that an oversight?
Could also expand the docs for phase and inPhase and document when to use which API in the future?
There was a problem hiding this comment.
Yes, there are a couple places where the inPhase pattern doesn't apply so cleanly, such as in ngc-wrapped where the compiler may not support performance tracing at all, or in program.ts where wrapping the operations in a function would cause problems with the flow of types through that particular section.
a3cb9b4 to
f862827
Compare
IgorMinar
left a comment
There was a problem hiding this comment.
in general LGTM. Please consider/address the feedback posted my previous comment.
f862827 to
be71f52
Compare
ngtsc has an internal performance tracing package, which previously has not really seen much use. It used to track performance statistics on a very granular basis (microseconds per actual class analysis, for example). This had two problems: * it produced voluminous amounts of data, complicating the analysis of such results and providing dubious value. * it added nontrivial overhead to compilation when used (which also affected the very performance of the operations being measured). This commit replaces the old system with a streamlined performance tracing setup which is lightweight and designed to be always-on. The new system tracks 3 metrics: * time taken by various phases and operations within the compiler * events (counters) which measure the shape and size of the compilation * memory usage measured at various points of the compilation process If the compiler option `tracePerformance` is set, the compiler will serialize these metrics to a JSON file at that location after compilation is complete.
A previous commit implemented a streamlined performance metric reporting system for the compiler-cli, controlled via the compiler option `tracePerformance`. This commit adds a custom Bazel flag rule //packages/compiler-cli:ng_perf to the repository, and wires it through to the `ng_module` implementation such that if the flag is set, `ng_module` will produce perf results as part of the build. The underlying mechanism of `//:ng_perf` is not exported from `@angular/bazel` as a public rule that consumers can use, so there is little risk of accidental dependency on the contents of these perf traces. An alias is added so that `--ng_perf` is a Bazel flag which works in our repository.
be71f52 to
314f36a
Compare
…41125) ngtsc has an internal performance tracing package, which previously has not really seen much use. It used to track performance statistics on a very granular basis (microseconds per actual class analysis, for example). This had two problems: * it produced voluminous amounts of data, complicating the analysis of such results and providing dubious value. * it added nontrivial overhead to compilation when used (which also affected the very performance of the operations being measured). This commit replaces the old system with a streamlined performance tracing setup which is lightweight and designed to be always-on. The new system tracks 3 metrics: * time taken by various phases and operations within the compiler * events (counters) which measure the shape and size of the compilation * memory usage measured at various points of the compilation process If the compiler option `tracePerformance` is set, the compiler will serialize these metrics to a JSON file at that location after compilation is complete. PR Close #41125
A previous commit implemented a streamlined performance metric reporting system for the compiler-cli, controlled via the compiler option `tracePerformance`. This commit adds a custom Bazel flag rule //packages/compiler-cli:ng_perf to the repository, and wires it through to the `ng_module` implementation such that if the flag is set, `ng_module` will produce perf results as part of the build. The underlying mechanism of `//:ng_perf` is not exported from `@angular/bazel` as a public rule that consumers can use, so there is little risk of accidental dependency on the contents of these perf traces. An alias is added so that `--ng_perf` is a Bazel flag which works in our repository. PR Close #41125
A previous commit implemented a streamlined performance metric reporting system for the compiler-cli, controlled via the compiler option `tracePerformance`. This commit adds a custom Bazel flag rule //packages/compiler-cli:ng_perf to the repository, and wires it through to the `ng_module` implementation such that if the flag is set, `ng_module` will produce perf results as part of the build. The underlying mechanism of `//:ng_perf` is not exported from `@angular/bazel` as a public rule that consumers can use, so there is little risk of accidental dependency on the contents of these perf traces. An alias is added so that `--ng_perf` is a Bazel flag which works in our repository. PR Close #41125
…ngular#41125) ngtsc has an internal performance tracing package, which previously has not really seen much use. It used to track performance statistics on a very granular basis (microseconds per actual class analysis, for example). This had two problems: * it produced voluminous amounts of data, complicating the analysis of such results and providing dubious value. * it added nontrivial overhead to compilation when used (which also affected the very performance of the operations being measured). This commit replaces the old system with a streamlined performance tracing setup which is lightweight and designed to be always-on. The new system tracks 3 metrics: * time taken by various phases and operations within the compiler * events (counters) which measure the shape and size of the compilation * memory usage measured at various points of the compilation process If the compiler option `tracePerformance` is set, the compiler will serialize these metrics to a JSON file at that location after compilation is complete. PR Close angular#41125
A previous commit implemented a streamlined performance metric reporting system for the compiler-cli, controlled via the compiler option `tracePerformance`. This commit adds a custom Bazel flag rule //packages/compiler-cli:ng_perf to the repository, and wires it through to the `ng_module` implementation such that if the flag is set, `ng_module` will produce perf results as part of the build. The underlying mechanism of `//:ng_perf` is not exported from `@angular/bazel` as a public rule that consumers can use, so there is little risk of accidental dependency on the contents of these perf traces. An alias is added so that `--ng_perf` is a Bazel flag which works in our repository. PR Close angular#41125
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |


No description provided.