graph-node icon indicating copy to clipboard operation
graph-node copied to clipboard

GraphQL parse/validation caching

Open dotansimha opened this issue 3 years ago • 3 comments

Since GraphQL parse and validate phase are static (does not depend on the user input like variables), we can implement caching for both phases (for parser: String => query::Document, for validation: String | query::Document => Vec<ValidationError>).

This might be more relevant once https://github.com/graphprotocol/graph-node/pull/3057 lands, because if we'll add more validation rules it might add some (probably minimal) overhead.

Usually it's implemented with LRU.

dotansimha avatar Dec 16 '21 16:12 dotansimha

That's a good idea! For our purposes, I think it would be enough to keep a HashSet of the shape hashes of the queries that were successfully validated. We already calculate that hash (a u64) for all queries anyway. And since it's so little data, I don't think we have to worry about cache eviction and just keep those hashes for the lifetime of the service.

lutter avatar Dec 22 '21 00:12 lutter

https://github.com/graphprotocol/graph-node/pull/3188#issuecomment-1021490277

dotansimha avatar Jan 25 '22 18:01 dotansimha

Reopened, due to the high CPU issue we recently had with GraphQL validations.

dotansimha avatar Jul 20 '22 11:07 dotansimha