{"action":"created","issue":{"url":"https://api.github.com/repos/mapbox/mapbox-gl-js/issues/1352","labels_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/issues/1352/labels{/name}","comments_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/issues/1352/comments","events_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/issues/1352/events","html_url":"https://github.com/mapbox/mapbox-gl-js/pull/1352","id":91990594,"number":1352,"title":"Batch mode for efficiently mutating Style instances","user":{"login":"scothis","id":302992,"avatar_url":"https://avatars.githubusercontent.com/u/302992?v=3","gravatar_id":"","url":"https://api.github.com/users/scothis","html_url":"https://github.com/scothis","followers_url":"https://api.github.com/users/scothis/followers","following_url":"https://api.github.com/users/scothis/following{/other_user}","gists_url":"https://api.github.com/users/scothis/gists{/gist_id}","starred_url":"https://api.github.com/users/scothis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scothis/subscriptions","organizations_url":"https://api.github.com/users/scothis/orgs","repos_url":"https://api.github.com/users/scothis/repos","events_url":"https://api.github.com/users/scothis/events{/privacy}","received_events_url":"https://api.github.com/users/scothis/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/mapbox/mapbox-gl-js/labels/in%20progress","name":"in progress","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-30T05:42:06Z","updated_at":"2015-06-30T06:23:27Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/1352","html_url":"https://github.com/mapbox/mapbox-gl-js/pull/1352","diff_url":"https://github.com/mapbox/mapbox-gl-js/pull/1352.diff","patch_url":"https://github.com/mapbox/mapbox-gl-js/pull/1352.patch"},"body":"Mutation operations on a Style instance are designed to be atomic.\r\nDepending on the operation, there is a significant amount of work that\r\nmust be preformed to flush and recreate state. This work is wasted when\r\nmultiple mutation methods are invokes sequentially.\r\n\r\nBatching these mutations allows deferring this work until the batch is\r\ncomplete and deduping the work.\r\n\r\n    map.batch(function(batch) {\r\n        batch.addLayer(layer1);\r\n        batch.addLayer(layer2);\r\n        ...\r\n        batch.addLayer(layerN);\r\n    });\r\n\r\nMethods on the batch object provided to the work function mirror methods\r\non Map and Style, and include:\r\n- addLayer\r\n- removeLayer\r\n- setPaintProperty\r\n- setLayoutProperty\r\n- setFilter\r\n- addSource\r\n- removeSource\r\n\r\nInternally, calls to four methods are deferred:\r\n- style._groupLayers (will only fire once)\r\n- style._broadcastLayers (will only fire once)\r\n- style._reloadSource (will fire once per source)\r\n- style.fire (each call will fire)\r\n\r\nA casual benchmark shows the time to add 80 layers dropping from ~800 ms\r\nto ~20 ms when run as a batch.\r\n\r\nIssue: #1341"},"comment":{"url":"https://api.github.com/repos/mapbox/mapbox-gl-js/issues/comments/117008940","html_url":"https://github.com/mapbox/mapbox-gl-js/pull/1352#issuecomment-117008940","issue_url":"https://api.github.com/repos/mapbox/mapbox-gl-js/issues/1352","id":117008940,"user":{"login":"jfirebaugh","id":98601,"avatar_url":"https://avatars.githubusercontent.com/u/98601?v=3","gravatar_id":"","url":"https://api.github.com/users/jfirebaugh","html_url":"https://github.com/jfirebaugh","followers_url":"https://api.github.com/users/jfirebaugh/followers","following_url":"https://api.github.com/users/jfirebaugh/following{/other_user}","gists_url":"https://api.github.com/users/jfirebaugh/gists{/gist_id}","starred_url":"https://api.github.com/users/jfirebaugh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jfirebaugh/subscriptions","organizations_url":"https://api.github.com/users/jfirebaugh/orgs","repos_url":"https://api.github.com/users/jfirebaugh/repos","events_url":"https://api.github.com/users/jfirebaugh/events{/privacy}","received_events_url":"https://api.github.com/users/jfirebaugh/received_events","type":"User","site_admin":false},"created_at":"2015-06-30T06:23:27Z","updated_at":"2015-06-30T06:23:27Z","body":"This looks great. Only adjustment I suggest is to ensure that a style `change` event fires only once per batch."}}