eclipse-ee4j / eclipse-ee4j/yasson

JsonArray serialisation seems really really slow

Open
#657 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
218
Forks
109
Avg merge
1d 5h
Merged PRs (30d)
9

Description

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> curveForSpreadGroups = callCurvesForSpreadGroups;
// but if put use puts
if(false == isCall)
{
curveForSpreadGroups = putCurvesForSpreadGroups;
}

// get update delta
List 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 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 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);

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.