Quickly change plot type between 3D lines and surface

So I want to plot a 3D plot where I can change the plot type dynamically between surface and scatter3d-line type, the line plot uses multiple line to plot the surface. Following is the code I’m using, It works but it’s extremely slow. Here xx,yy,zz all are 2 dimensional data array. lIniData and sIniData are data to setup plot initially for 3d lines and surface respectvely with lIniData and xx having same length. As current performance this function takes 2 sec to change from line to surface and 5-8 sec for surface to line.
Is there any easy and fast way to achieve this

    function updatePlot() {
        var cur = figurecontainer.data[0].type;  // current plot type
        var val = sel.selectedIndex;            //plot type I want to change into
        if(val == 0){                           //val 0 means 3d lines and 1 is surface
                Plotly.newPlot(figurecontainer, lIniData , layout);  //plots scatter3d-line
            Plotly.restyle(figurecontainer, {'x': xx,'y': yy,'z': zz });
        } else{
                Plotly.newPlot(figurecontainer, sIniData , layout); //plots surface
            Plotly.restyle(figurecontainer,  {"x" : [xx], "y" : [yy], "z": [zz]} )

Combining the newPlot and restyle calls into one would be a good start.

Yeah, that’s what I’m thinking too. But surface plot has only one trace while the line plot has multiple traces to plot the surface with multiple 3d lines, and restyle only changes the behaviour of existing traces right? it can’t modify the number of traces. So how can I do that?