question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SupplierUtil.createSupplier returns a slow supplier

See original GitHub issue

Issue

https://github.com/jgrapht/jgrapht/blob/master/jgrapht-core/src/main/java/org/jgrapht/util/SupplierUtil.java#L58

Calls getDeclaredConstructor every time.

Expected behaviour

Hoist the call to getDeclaredConstructor and close over it.

    @Nonnull
    public static <T> Supplier<T> createSupplier(Class<? extends T> edgeClass) {
        try {
            Constructor<? extends E> constructor = edgeClass.getDeclaredConstructor();
            return () -> {
                try {
                    return constructor.newInstance();
                } catch (ReflectiveOperationException e) {
                    throw new RuntimeException(e);
                }
            };
        } catch (ReflectiveOperationException | SecurityException e) {
            throw new RuntimeException(e);
        }
    }

Conclusions

LOL another performance issue from those random idiots who are doing WTF? 😄 😄

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
d-michailcommented, Oct 1, 2019

I am mostly concerned with stuff like adjusting permissions using reflection. I can certainly try testing the resulting code w.r.t AOT before we merge anything.

0reactions
d-michailcommented, Feb 13, 2020

I tested AOT and there is no problem with this change.

Closing this one in favor of version with proper serialization (#821).

Read more comments on GitHub >

github_iconTop Results From Across the Web

SupplierUtil (JGraphT : a free Java graph library)
Create a long supplier which returns a sequence starting from a specific numbers. Create a string supplier which returns random UUIDs.
Read more >
2023116 - How to Create a Supplier Return Without a Reference
Go to the Outbound Logistics work center; Go to the Common Tasks and select New Return to Supplier; You are not able to...
Read more >
Is it possible to declare that a Supplier<T> needs to throw an ...
Considering the above, why not create a new interface and declare the getWithIO method in ... requireNonNull(supplier); try { return supplier.get(); } catch ......
Read more >
Supplier Returns Without Receipts - Oracle Help Center
You can return goods to a supplier without referencing the original receipt. This is useful when returning goods with a receipt reference isn't...
Read more >
Index (resilience4j-core 1.7.1 API) - javadoc.io
SupplierUtils. Returns a composed function that first applies the Supplier and then applies either the resultHandler or exceptionHandler.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found