formio.js icon indicating copy to clipboard operation
formio.js copied to clipboard

Form running slow with lots of custom logic

Open CoreNetJC opened this issue 7 years ago • 11 comments

We have a pretty lengthy form with approximately 700 yes/no questions inside about 40 panels. Each panel has some advanced logic for showing the panel and about 50% of the questions have a conditional on them to show/hide the question based on the question above it.

Problem 1: The form is slow - taking approx 2-5 seconds to update anytime anything is selected. Problem 2: "Logic" tab does not seem to work. We had to write custom javascript to show/hide each panel due to the logic not working. The custom logic does seem to work properly.

Is there anything we can do to speed up the form? Would getting the logic to work and removal of the custom javascript speed things up, or would it amount to the same issue? Just curious if perhaps the custom logic we are using would run slower than using the provided "logic" tab for each panel. We need logic, versus conditional, due to 2-3 conditions needing to be met before showing/hiding a given panel.

Willing to discuss expediting if necessary.

CoreNetJC avatar Mar 11 '19 17:03 CoreNetJC

Hey @ProteanHub,

Sorry you are having issues. A form should work just fine with 700 yes/no questions, so this tells me that you are running into an infinite onchange issue that has caused performance problems with other forms that we have debugged having similar issues. To determine if you have hit an infinite on change issue, you can add the following to your form logic.

Formio.createForm(document.getElementById('formio'), 'https://yourproject.form.io/yourform').then((form) => {
  form.on('change', (change) => {
    console.log(change);
  });
});

If you see this change event going crazy without ever stopping then this tells me that is the source of the problem. We are able to debug the source of this for you if you would like (with paid support) or you can step through the event loop to determine why the form values appear to be constantly changing back and forth between states (which is what usually causes this problem). In some cases you may have conflicting conditions.. For example, where field A changes value of B, and B changes value of A.

As for logic, we do know it works for simple cases but have heard of it failing for more complex forms. This may be something that we could also look into. Here is a "simple" example of it working.

http://formio.github.io/formio.js/app/examples/fieldLogic.html

It may help if you provide some examples of your logic not working so we can debug on our end.

Again sorry you are having issues, but we have successfully debugged forms like this in the past and I am confident we can get to the bottom of the form performance issues.

Thanks,

Travis.

travist avatar Mar 11 '19 20:03 travist

Thanks @travist I appreciate the quick response. That code only brings up a single item during each change.

I will contact Denise and reference this issue so we can get the ball rolling on having you take a look.

CoreNetJC avatar Mar 11 '19 21:03 CoreNetJC

@ProteanHub so we just introduced a new feature that may be able to help this situation with long forms and load times. We had another customer that had many "sections" within "collapsed panels" and they were complaining about the same performance problems. They had over 5000 fields in their form. We introduced a new "lazy load" feature on panels where it will hold off on rendering the panel until the user clicks to expand this panel. We saw enormous performance improvements because of this. If you want to try this out on our hosted service, then goto https://beta.form.io where you will see the following configuration.

Alt text

The only caveat is that this currently does not work if you have "calculated" values that are dependent on a collapsed panel. We are still working on a possible solution for that, but it may be possible you can design your form in a way where the calculations and dependencies are isolated per panel.

Let us know if this helps your situation.

travist avatar Mar 14 '19 15:03 travist

Just downloaded the newest version, thanks. When I enable that setting, it deletes all the content within the panel upon saving.

CoreNetJC avatar Mar 14 '19 17:03 CoreNetJC

After more testing, I am finding that the panel keeps closing (while in the editor) on our local system. I can open it up, then drag a component into the panel, and it instantly closes again. The link you sent doesn't do that, but it appears you are using the angular version for beta.form.io and we are using the pure javascript version for our system.

If I save the form with it collapsed, it deletes all the items in that panel. If I open it up, then save it, all appears normal.

In the end, this may indeed work for us if we can trigger the panel to open when a question above it is answered in a certain way.

CoreNetJC avatar Mar 14 '19 19:03 CoreNetJC

Yeah, we just found this issue in our testing and has already been fixed. Sorry about that. Please try again.

travist avatar Mar 14 '19 20:03 travist

Are you kidding me, thanks for being so responsive! I will take a look tonight.

CoreNetJC avatar Mar 14 '19 21:03 CoreNetJC

It is much improved with the lazy loading. Not quite 100%, but certainly workable. Is there a way to open a given panel up when it is triggered through a condition?

CoreNetJC avatar Mar 15 '19 04:03 CoreNetJC

I would have to test this, but am not sure how this will behave with conditions.

travist avatar Mar 15 '19 14:03 travist

The conditions work well on our end and shows the panel initially collapsed. I tried setting instance.collapsed=false and instance.component.collapsed = false inside of the advanced conditional with no effect.

CoreNetJC avatar Mar 15 '19 14:03 CoreNetJC

I think it would be this.

if (instance.collapsed) {
  instance.toggleCollapse();
}

travist avatar Mar 16 '19 02:03 travist