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

First invocation of Event.parse(tsv) takes much longer than subsequent invocations #136

Open
arthur78 opened this issue Aug 13, 2024 · 1 comment

Comments

@arthur78
Copy link

arthur78 commented Aug 13, 2024

Hi guys,

I'm using 3.2.1 version of SDK in a Java application. When I run a unit test doing several parse calls in a row, I see that the very first call is taking significantly more time than the rest.

Here's a function called by the unit test several times in a loop:

protected static String tsv2json(String sourceEventInTsv) {
    long startTime = System.currentTimeMillis();
    Validated<ParsingError, Event> validatedEvent = Event.parse(sourceEventInTsv);
    long endTime = System.currentTimeMillis();
    long executionTime = endTime - startTime;
    System.out.println("Execution time in milliseconds: " + executionTime);
    if (validatedEvent.isValid()) {
        Event event = validatedEvent.toOption().get();
        return event.toJson(true).noSpaces(); 
    }
    throw new InvalidSnowplowEvent(String.format("Invalid Snowplow event in TSV [%s]: %s",
            validatedEvent.toString(), sourceEventInTsv));
}

The test is run on a new M3 Mac, openJDK@21, for example:

Execution time in milliseconds: 173
Execution time in milliseconds: 1
Execution time in milliseconds: 2
Execution time in milliseconds: 1
Execution time in milliseconds: 2
Execution time in milliseconds: 2
Execution time in milliseconds: 1
Execution time in milliseconds: 1
Execution time in milliseconds: 1

The TSV fixture strings are about 4000-6000 chars length.

Could you please take a look and let me know if there's something wrong here. Thank you.

@arthur78
Copy link
Author

On the lambda with 768 MB allocated memory, the first conversion takes ~4 seconds.

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

No branches or pull requests

1 participant