Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline xml writing into Event class #3539

Merged
merged 7 commits into from
Nov 7, 2024
Merged

Inline xml writing into Event class #3539

merged 7 commits into from
Nov 7, 2024

Conversation

rakow
Copy link
Contributor

@rakow rakow commented Nov 5, 2024

The current XML event writer is very inefficient. For every event that needs to be written:

  • A map is created
  • Attributes put into the map and often converted to a new string object
  • Every attribute will be XML encoded
    • Which is not needed for primitives
    • Creates a new string in case the attribute needs to be encoded
  • Multiple calls to a BufferedWriter are made
    • Which is a synchronized data structure and not very efficient with a lot of invocations

This PR moves the serialization code to the events itself and makes use of a StringBuilder.
Event classes are responsible to write their xml representation via writeAsXML(StringBuilder out) directly to the builder. Using this approach, not a single new object needs to be allocated for writing an event.

Events who don't overwrite this method will use the old behavior. The resulting output should be 100% identical.
For now writeAsXML was implemented for the most often used events and more may be added in further PRs.

In a quick test on a realistic but not terrible large scenario, the mobsim was roughly speed up by 10%.

@rakow rakow enabled auto-merge (squash) November 7, 2024 13:00
@rakow rakow merged commit 9cb2069 into master Nov 7, 2024
49 checks passed
@rakow rakow deleted the inline-xml-writing branch November 7, 2024 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant