[ 
https://issues.apache.org/jira/browse/CONFIGURATION-596?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Vladimir Sitnikov updated CONFIGURATION-596:
--------------------------------------------
    Attachment: CoWArrayList1.jpg
                dataflow_commons_configuration_cowarraylist.png

{quote}Do you have concrete numbers that these objects acutally cause a 
measurable overhead?{quote}

That's a good question. Those CowLists alone are 1-2% of all the allocations -- 
see JFR report attached.
Note, that each CowList always creates ReentrantLock and that ReentrantLock 
creates Sync inside.
So the overall impact is higher (it is not included .

{quote}We could create them with a low initial capacity (as most applications 
are not expected to register many listeners), but this will only save a few 
bytes.{quote}
I do not think you can. There is no such thing as "initial capacity" for copy 
on write lists :)

{quote} null checks would have to be added, and you would need a means of 
synchronization to ensure thread-safe access{quote}
I believe null checks would not have overhead since the runtime anyway performs 
the check (to throw NPE if the value is null).

{quote} you would need a means of synchronization to ensure thread-safe 
access{quote}
Sure. However COWList is properly synchronized, so we need just enable 
properly-synchronized instantiation.

Either double-checked locking (volatile COWList + synchronize on EventSource) 
or volatile COWList + AtomicReferenceFieldUpdater would do.

{quote}In addition, some concrete configuration implementations register a 
special error listener which just logs occurring exceptions; in such cases, 
nothing is gained{quote}
Do you mean there are cases when at least a single listener is added?
I'll check my heap dumps for the cases of initialized vs empty lists.

> Allow event listener Collections to be lazily created in event.EventSource
> --------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-596
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-596
>             Project: Commons Configuration
>          Issue Type: Improvement
>          Components: Events & Notifications
>    Affects Versions: 1.9
>            Reporter: Vladimir Sitnikov
>         Attachments: CoWArrayList1.jpg, 
> dataflow_commons_configuration_cowarraylist.png
>
>
> It turns out every instance of {{AbstractConfiguration}} creates a couple of 
> {{CopyOnWriteAraryLists}} for {{event.EventSource}}.
> In our usage patterns in most of the cases the lists are not used.
> Can the lists be lazy-initialized? (that is created on the first addListener 
> request)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to