{"action":"created","issue":{"url":"https://api.github.com/repos/ioam/param/issues/123","repository_url":"https://api.github.com/repos/ioam/param","labels_url":"https://api.github.com/repos/ioam/param/issues/123/labels{/name}","comments_url":"https://api.github.com/repos/ioam/param/issues/123/comments","events_url":"https://api.github.com/repos/ioam/param/issues/123/events","html_url":"https://github.com/ioam/param/pull/123","id":146481553,"number":123,"title":"Add shared parameter context manager","user":{"login":"philippjfr","id":1550771,"avatar_url":"https://avatars.githubusercontent.com/u/1550771?v=3","gravatar_id":"","url":"https://api.github.com/users/philippjfr","html_url":"https://github.com/philippjfr","followers_url":"https://api.github.com/users/philippjfr/followers","following_url":"https://api.github.com/users/philippjfr/following{/other_user}","gists_url":"https://api.github.com/users/philippjfr/gists{/gist_id}","starred_url":"https://api.github.com/users/philippjfr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philippjfr/subscriptions","organizations_url":"https://api.github.com/users/philippjfr/orgs","repos_url":"https://api.github.com/users/philippjfr/repos","events_url":"https://api.github.com/users/philippjfr/events{/privacy}","received_events_url":"https://api.github.com/users/philippjfr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-04-07T01:28:40Z","updated_at":"2016-04-07T21:39:22Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ioam/param/pulls/123","html_url":"https://github.com/ioam/param/pull/123","diff_url":"https://github.com/ioam/param/pull/123.diff","patch_url":"https://github.com/ioam/param/pull/123.patch"},"body":"This PR adds the ``shared_parameters`` context manager. Here's the docstring, which should explain what it does:\r\n\r\nContext manager to share parameter instances when creating\r\nmultiple Parameterized objects of the same type. Parameter default\r\nvalues are instantiated once and cached to be reused when another\r\nParameterized object of the same type is instantiated.\r\nCan be useful to easily modify large collections of Parameterized\r\nobjects at once and can provide a significant speedup.\r\n\r\nI've done some basic profiling and this can be a significant boost when instantiating a lot of complex objects.\r\n\r\n```python\r\n%%timeit\r\nwith param.parameterized.shared_parameters():\r\n    hmap = hv.HoloMap({i: hv.Image(np.random.rand(10,10)) for i in range(10000)})\r\n```\r\n\r\n```\r\n1 loop, best of 3: 1.77 s per loop\r\n```\r\n\r\nvs.\r\n\r\n```python\r\n%%timeit\r\nhv.HoloMap({i: hv.Image(np.random.rand(10,10)) for i in range(10000)})\r\n```\r\n\r\n```\r\n1 loop, best of 3: 3.86 s per loop\r\n```\r\n\r\nThere's many cases where this might be useful, particularly holoviews where many operations create a lot of identical objects (e.g. groupby). Sharing a parameter value can also be useful in it's own right since you could change the dimensions of all the elements at once (although I might not recommend it):\r\n\r\n```python\r\nwith param.shared_parameters():\r\n    hmap = hv.HoloMap({i: hv.Image(np.random.rand(10,10)) for i in range(10000)})\r\nhmap.last.kdims[:] = [hv.Dimension('A'), hv.Dimension('B')]\r\n```"},"comment":{"url":"https://api.github.com/repos/ioam/param/issues/comments/207098411","html_url":"https://github.com/ioam/param/pull/123#issuecomment-207098411","issue_url":"https://api.github.com/repos/ioam/param/issues/123","id":207098411,"user":{"login":"philippjfr","id":1550771,"avatar_url":"https://avatars.githubusercontent.com/u/1550771?v=3","gravatar_id":"","url":"https://api.github.com/users/philippjfr","html_url":"https://github.com/philippjfr","followers_url":"https://api.github.com/users/philippjfr/followers","following_url":"https://api.github.com/users/philippjfr/following{/other_user}","gists_url":"https://api.github.com/users/philippjfr/gists{/gist_id}","starred_url":"https://api.github.com/users/philippjfr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/philippjfr/subscriptions","organizations_url":"https://api.github.com/users/philippjfr/orgs","repos_url":"https://api.github.com/users/philippjfr/repos","events_url":"https://api.github.com/users/philippjfr/events{/privacy}","received_events_url":"https://api.github.com/users/philippjfr/received_events","type":"User","site_admin":false},"created_at":"2016-04-07T21:39:22Z","updated_at":"2016-04-07T21:39:22Z","body":"My suggestion for holoviews is that we would use it in a few select places where the generated objects are guaranteed to be identical except for their ``.data`` value. The main example being ``Columns.groupby``, where you're creating a lot of individual Elements with subsets of the data. In that example most parameters are already shared because the same parameter values are passed to all Element instances or they are inherited via clone, which also does not copy instances."}}