0

I'm currently developing an Angular/Groovy Application and have a very slow performance by marshaling a payload in backend (groovy). It needs a very long time to get it finish, send it to frontend and render.

In backend I have:

def getAll(String userName) {
    def payload = marshalSteps(Step.findAllByUserName(userName))

    if (payload.size() <= 0) {
        payload = NO_STEPS
    }

    payload
}

marshalSteps looks like this:

private static def marshalSteps(List<Step> steps) {
    def payload = []

    steps.each {
        payload << marshalMinimalStep(it)
    }

    payload
}

Because we send different marshaling for every request, marshalMinimalStep looks like:

private static def marshalMinimalStep(Step step) {
    def payload = [
            id              : step.id,
            name            : step.name,
            names           : marshalTranslation(step.names),
            shortcut        : step.shortcut,
            week            : step.week.doubleValue(),
            isRelevant      : step.isRelevant
    ]

    payload
}

In frontend I'm using ng-repeat to display all the steps.

<ul class="list-group" ng-show="stepCtrl.steps.length > 0">
        <div ng-repeat="step in stepCtrl.steps | orderBy:'name' track by step.id">
            <div class="col-md-10">
                <li class="list-group-item overview" ng-click="stepCtrl.edit(step.id)">
                    <display-name translations="step.names"></display-name>
                    <span class="pull-right">{{step.week}}</span>
                </li>
            </div>
        </div>
    </ul>

I have around 9.000 steps and need around 150,000ms to perform that getAll() method and render the steps in frontend, which is too slow.

What can I do to improve the performance?

Do I have to bulk-fetching in Hibernate, like sessionFactory.currentSession.clear()?

I put also the marshalTranslation() as a part of the question.

private static def marshalTranslation(List<Translation> translations) {
     def payload = []
     translations.each {
         payload << [
            language: it.language,
            content : it.content
         ]
    }
    payload
}
blown.eye
  • 1
  • 2

1 Answers1

0

Ok, total guess, but can you try replacing:

def payload = []

steps.each {
    payload << marshalMinimalStep(it)
}

With

def payload = steps.collect { marshalMinimalStep(it) }

And see if it's quicker?

Probably not what does marshalTranslation do?

tim_yates
  • 167,322
  • 27
  • 342
  • 338
  • marshalTranslation() is to get all the translation of step's name in multi language (We have currently 6 languages) I just tried your suggestion. Logs said it needs almost a half of time like I did before. But to completly render it out I need now 2 times longer. – blown.eye Mar 23 '18 at 11:05
  • Pardon. My Mistake. I read the wrong logs. It still need a same time like before. – blown.eye Mar 23 '18 at 11:10
  • I guess it's `marshallTranslation` that's taking the time then... Can you share it? – tim_yates Mar 23 '18 at 11:18
  • I updated the question and put the marshalTranslation() there. – blown.eye Mar 23 '18 at 11:40
  • Can't see why that would be slow... Which leads us back to `User.findAllByUserName` being the culprit... Can you put some logging in the code to verify that it's this line that takes a long time? – tim_yates Mar 23 '18 at 12:31
  • I added time logger for that. It need only 3654 ms to perform `Step.findAllByUserName()`. I think, it's acceptable. – blown.eye Mar 23 '18 at 13:08
  • It's not a batch insert though is it? – tim_yates Mar 23 '18 at 13:16
  • Oh... This is making a call to grails per user isn't it? The penny had just dropped – tim_yates Mar 25 '18 at 08:45
  • After some logging and debugging, I come to a conclusion that the problem is by frontend. It's need to much time to render. – blown.eye Mar 26 '18 at 09:12