Skip to content

Conversation

@michaeladler
Copy link
Contributor

Summary

This may seem like a mundane merge request, but it delivers significant performance improvements. Benchmarks show that this library now outperforms jsonld.js.

Note: While the changes may appear straightforward, caution is required when implementing them. It is sometimes necessary to differentiate between a value explicitly set to null in the context and one that is simply absent.

PS: I don't have any other changes lined up (I couldn't submit this PR earlier because it builds upon #82 to avoid merge conflicts).

Details:

  • Replace maps with structs to achieve significant performance gains.
  • Improve type-safety. Previously, type confusion resulted in unnecessary checks, such as comparing a known string value against a boolean.
  • Ensure defaultLanguage always contains a language. Previously, a missing if-check could result in defaultLanguage being set to "_%s", with %s being the direction.
  • Remove GetKeysString since it's not used anywhere and is equivalent to the generic GetKeys now.

Basic example

No change in behavior.

Motivation

Performance! Additionally, the struct-based design enhances code navigation/reasoning (especially when using an LSP).

Checks

  • Passes make test

- Replace maps with structs to achieve significant performance gains.
  (Benchmarks show that this implementation is now faster than
  jsonld.js.)
- Improve type-safety. Previously, type confusion resulted in
  unnecessary checks, such as comparing a known string value against a
  boolean.
- Ensure defaultLanguage always contains a language. Previously,
  a missing if-check could result in defaultLanguage being set to
  "_%s", with %s being the direction.
- Remove GetKeysString since it's not used anywhere and is equivalent to
  the generic GetKeys now.

Signed-off-by: Michael Adler <michael.adler@siemens.com>
@kazarena
Copy link
Member

@michaeladler, the idea behind this PR makes sense. I can see why it improves performance.

The changes are substantial, and I'm still going through it line by line to ensure it does the right things. Apologies for the delay. I should finish the review this week.

@michaeladler
Copy link
Contributor Author

No problem, I completely understand. Thank you for your thorough review. The test suite is excellent though: it caught every mistake I made (such as using bool instead of *bool for ternary semantics) and really helped me stay on track. A great exercise in refactoring :)

Copy link
Member

@kazarena kazarena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks good. Happy to merge.

@kazarena kazarena merged commit 5eec423 into piprate:master Jul 14, 2025
3 checks passed
@michaeladler michaeladler deleted the feat/refactor-maps branch July 15, 2025 06:33
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.

2 participants