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

Bytecode instrumentation cache #229

Merged
merged 2 commits into from
Aug 16, 2023
Merged

Bytecode instrumentation cache #229

merged 2 commits into from
Aug 16, 2023

Conversation

eupp
Copy link
Collaborator

@eupp eupp commented Aug 10, 2023

Currently bytecode instrumentation can take significant time. Moreover, it is performed for each scenario even when testing the same data structure.

In the context of the adaptive planning feature #158, instrumentation time can interfere with the invocations time, thus making it harder to get reliable prediction for the average invocation time.

This PR provides simple instrumented bytecode caching, thus mitigating the performance overhead of instrumentation.

eupp added 2 commits August 10, 2023 18:47
Signed-off-by: Evgenii Moiseenko <[email protected]>
@eupp eupp requested a review from ndkoval August 10, 2023 16:48
@eupp eupp changed the title Bytecode instrumentation cache. Bytecode instrumentation cache Aug 10, 2023
byte[] bytes = instrument(originalName(name));
byte[] bytes = null;
if (bytecodeCache != null) {
bytes = bytecodeCache.get(name);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use putIfAbscent(..) { .. } instead

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the usage of computeIfAbsent in fact makes code more verbose, because:

  1. instrument throws checked exception IOException which has to be handled inside lambda.
  2. bytecodeCache might be null and it is Java file, so we cannot use Kotlin's ? syntax sugar.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is how the code looks like:

                if (bytecodeCache != null) {
                    bytes = bytecodeCache.computeIfAbsent(name, className -> {
                            try {
                                return instrument(originalName(className));
                            } catch (IOException e) {
                                throw new RuntimeException(e);
                            }
                        }
                    );
                } else {
                    bytes = instrument(originalName(name));
                }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove checked exception from instrument, but still after this there would be two similar calls to instrument (in case when we have the cache, and when we don't)

@eupp eupp merged commit b148b15 into develop Aug 16, 2023
@eupp eupp deleted the instrumentation-cache branch August 16, 2023 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants