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

Enable concurrenct access to SchemaLoader #323

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

marwan-at-work
Copy link

Adds a type-safe wrapper for the standard library's sync.Map as it fits the usecase of how gojsonschema uses its internal pool: write once, read many.

Fixes xeipuuv/gojsonreference#9

@marwan-at-work
Copy link
Author

@xeipuuv Hi there 👋🏼 -- I noticed there hasn't been a commit in the last 3 years. Let me know if this library is still maintained and if this change is acceptable to you.

Thank you!

Copy link
Contributor

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

Thanks! Not a maintainer, but left a comment 🤗

Let do a quick attempt what it could look like with a RWMutex

Comment on lines +9 to +10
func (spd *schemaPoolDocuments) Load(key string) (*schemaPoolDocument, bool) {
val, ok := spd.mp.Load(key)
Copy link
Contributor

Choose a reason for hiding this comment

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

tbh, I wonder if the added complexity of using a sync.Map is needed for this use-case. sync.Map (by itself) does not have type-safety, so requires all the extra boilerplating in this file, and while sync.Map can perform better, in many situations it may actually be slower (unless high concurrency, large number of cores); https://medium.com/@deckarep/the-new-kid-in-town-gos-sync-map-de24a6bf7c2c

@thaJeztah
Copy link
Contributor

opened #324 as a possible alternative; let me know what you think 😅

@thaJeztah
Copy link
Contributor

/cc @johandorland PTAL

@marwan-at-work
Copy link
Author

marwan-at-work commented Feb 17, 2021

@thaJeztah It might be fun to benchmark the two alternatives in different scenarios. But I'm definitely glad with either solutions if one can get merged upstream :)

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.

Concurrency Support
2 participants