You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by "Andreas Veithen (JIRA)" <ji...@apache.org> on 2019/05/11 09:56:00 UTC

[jira] [Commented] (SYNAPSE-1102) Performance save - Replace instances of Math.Random with Random.nextDouble

    [ https://issues.apache.org/jira/browse/SYNAPSE-1102?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16837798#comment-16837798 ] 

Andreas Veithen commented on SYNAPSE-1102:
------------------------------------------

Your patch replaces {{Math.random()}} with {{new Random().nextDouble()}}. {{Math.random()}} has some overhead because it uses a shared {{Random}} instance and requires synchronization, but this only becomes relevant under high concurrency. {{new Random().nextDouble()}} has overhead because of object creation. It's not clear to me why that would be better. Probably the universally better solution would be to use {{ThreadLocalRandom.current().nextDouble()}}.

> Performance save - Replace instances of Math.Random with Random.nextDouble
> --------------------------------------------------------------------------
>
>                 Key: SYNAPSE-1102
>                 URL: https://issues.apache.org/jira/browse/SYNAPSE-1102
>             Project: Synapse
>          Issue Type: Improvement
>            Reporter: bd2019us
>            Assignee: Isuru Udana Loku Narangoda
>            Priority: Trivial
>         Attachments: SYNAPSE-1102.patch
>
>
> Some slight performance can be saved when replacing Math.random with Random.nextDouble, due to Math.random not having to create an instance of Random.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
For additional commands, e-mail: dev-help@synapse.apache.org