Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Performance hit of Thread.currentThread()

I suspect the advice is no longer necessarily correct or has been proven. Although there may be syscalls involved it is certainly the case that the native implementation can be fast-unlined through an intrinsic and it does not have to bail to an interpreter at all. 

https://github.com/dmlloyd/openjdk/blob/2368260acfb88a776d9d759cd1a30f4661e6e195/hotspot/src/share/vm/opto/library_call.cpp#L686

In addition almost all UI updates (including Swing, AWT, and the platforms that SWT supports) require that they be done from the correct thread so this isn't new at all. 

Where it could be optimised is removing the synchronised keyword of the get display thread, and/or add a new method "isDisplayThread()" without synchronisation so that there is less contention for the synchronised block in the Display class itself. There were some patches that were provided but they weren't accepted due to problems with adding new APIs to the builds not being testable. 

Alex

Sent from my iPhat 6

On 9 Jun 2016, at 23:10, Ned Twigg <ned.twigg@xxxxxxxxxxxx> wrote:

Most SWT method calls start with `checkWidget()`, which calls `Thread.currentThread()`.

I haven't profiled it myself, but Lint4j claims that this is an expensive method call:

Has anyone quantified the performance impact of these calls?

An alternative would be to introduce an `@SwtThread` annotation, and use `javaagent` to enable a "debug mode" where the thread is checked, and then not check them at runtime for release builds.

Here is a project which uses a similar approach for Swing:

Just curious if anyone else has looked at this :)

-Ned
_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev

Back to the top