Skip to content

JsonArray serialisation seems really really slow #657

Description

@dannyb2018

I am using yasson via the standard jakarta api to write out json. Performance without arrays seems ok but once there is an array suddenly it is orders of magnitude slower. I have included the code. Basically it has value that is different for different groups and so the array is a list of names of the group and then the values for the group. I have looked to see if anyone else had the same issue but apparently google search is basically useless now

    JsonObjectBuilder updateAJsonObjectBuilder = Json.createObjectBuilder();

    // get offset
    int updatedOffset = getUpdatedOffset(moneyness, triggerDelta, isCall);
    // get the collection of curves we are going to update
    // assume call
    Map<String, List<QPVolatilityPoint>> curveForSpreadGroups = callCurvesForSpreadGroups;
    // but if put use puts
    if(false == isCall)
    {
        curveForSpreadGroups = putCurvesForSpreadGroups;
    }

    // get update delta
    List<QPVolatilityPoint> fvCurve = curveForSpreadGroups.get("FV");
    QPVolatilityPoint volPointBeingUpdated = fvCurve.get(updatedOffset);

    // add moneyness
    updateAJsonObjectBuilder.add("moneyness", moneyness);

    // add update delta
    updateAJsonObjectBuilder.add("update_delta", volPointBeingUpdated.getDelta().getBigDecimal());

    // go through spread groups
    JsonArrayBuilder updatedVolPointsForSpreadGroupsAsJsonArray = Json.createArrayBuilder();
    Set<String> spreadGroupIdentifiers = curveForSpreadGroups.keySet();
    for(String currentSpreadGroupIdentifier : spreadGroupIdentifiers)
    {
        // get the current gorup
        QPPartyGroup currentSpreadCGroup = new QPPartyGroup();
        currentSpreadCGroup.parseIdentifier(currentSpreadGroupIdentifier);

        // create a record of the updated point
        JsonObjectBuilder updatedVolPointsForSpreadGroupAsJsonObjectBuilder = Json.createObjectBuilder();

        // add group name, name source and type
        updatedVolPointsForSpreadGroupAsJsonObjectBuilder.add("spread_group_name", currentSpreadCGroup.getName());
        updatedVolPointsForSpreadGroupAsJsonObjectBuilder.add("spread_group_name_source", currentSpreadCGroup.getNameSource());
        updatedVolPointsForSpreadGroupAsJsonObjectBuilder.add("spread_group_type", currentSpreadCGroup.getType());

        // add volume banded ivs
        JsonArrayBuilder volumeBandedIVsAsJsonArrayBuilder = Json.createArrayBuilder();
        // BUGBUGDB for now just zero bound ivs
        JsonObjectBuilder zeroBoundIVsAsJsonObjectBuilder = Json.createObjectBuilder();
        // add volume
        zeroBoundIVsAsJsonObjectBuilder.add("minimum_volume", 0);
        zeroBoundIVsAsJsonObjectBuilder.addNull("maximum_volume");
        // add iv
        // get the curve
        List<QPVolatilityPoint> curveForSpreadGroup = curveForSpreadGroups.get(currentSpreadGroupIdentifier);
        // get the vol point at that offset
        volPointBeingUpdated = curveForSpreadGroup.get(updatedOffset);
        // get iv and add it
        zeroBoundIVsAsJsonObjectBuilder.add("iv", volPointBeingUpdated.getImpliedVolatility().getBigDecimal());
        // add to volume bounded ivs
        volumeBandedIVsAsJsonArrayBuilder.add(zeroBoundIVsAsJsonObjectBuilder);

        // add to group update
        updatedVolPointsForSpreadGroupAsJsonObjectBuilder.add("implied_volatilities_by_volume", volumeBandedIVsAsJsonArrayBuilder);
        
        // add to list
        updatedVolPointsForSpreadGroupsAsJsonArray.add(updatedVolPointsForSpreadGroupAsJsonObjectBuilder);
    }
    // add array of updated ivs by spread group
    updateAJsonObjectBuilder.add("spread_adjusted_implied_volatilities", updatedVolPointsForSpreadGroupsAsJsonArray);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions