-
Notifications
You must be signed in to change notification settings - Fork 789
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
Sprockets 4.1.0 much slower due to changed header capitalisation #746
Comments
I don't see how that change would slowdown anything in sprockets, that change was just matching the behavior already existing in rack. Maybe it is related to the system test browser? |
That was my thought as well, so it was the last commit I tried to revert when looking into it, but I double confirmed my finding and tried two different browsers for the system test with the same result. Are you not seeing a slow down in system tests with sprockets 4.1.0? |
Nothing noticeable, no. Can you try to reproduce in a new app so we can try to isolate? |
A new app wouldn't have any meaningful tests in them. If it doesn't happen for you then we can park this until we find someone else who can corroborate, perhaps it's something odd in our infrastructure. I can monkey patch for now. |
Yeah, I'll keep this open. I'm really surprised that would have any impact given that is how the rack spec expects headers to be returned, as lowercase strings. Maybe something else is not following the rack spec and expecting thing to not be in lower case. |
@dhh did you notice any slowdown in your system test suite after upgrading sprockets to 4.1.0? |
Ok, I dug into this a bit deeper. It actually comes down to a single header "Cache-Control", as soon as you lower-case that in sprockets it breaks caching and sprockets has to serve up way more assets. On a hunch a grepped the stack for the word "Cache-Control" and I noticed that the rack gem (2.2.3.1) has the word "Cache-Control" in title case: when I monkey patched rack to use the lower case version it worked again. Long story short: the header "Cache-Control" needs to have the same capitalisation in Rack and in Sprockets. Rack plans to start using lower case headers in rack 3, but uses title case headers in rack 2. Not sure where to go from here. According to the RFC headers are case insensitive so rack is to blame, but they already fixed that in rack 3. Perhaps we can detect the rack version in Sprockets. Or perhaps this issue is not big enough and it will anyway resolve itself once rack 3 rolls around. I'm simply monkey patching the word "Cache-Control" in the code until then. Feel free to close the issue. |
Thank you for investigating this. I'll just revert t hat change. sprockets doesn't allow rack 3 yet. https://github.com/rails/sprockets/blob/main/sprockets.gemspec#L14 |
Who is actually using |
In other words, if the problem is in a Rack middleware doing |
@ioquatix > Who is actually using In rack I see these two lines doing a case-sensitive match for the existence of the Cache-Control header: |
I've started a discussion here about how we should handle Rack 2.x middleware: rack/rack#1915 |
This should be fixed in Rack 2.2.4, are you able to test? |
Yes, I can confirm it's fixed in rack 2.2.4, thank you! (Sprockets already rolled back the change to the header capitalisation, but I also tested it with the previous version that introduced lower case headers. There was no slowdown either way) |
Upgrading sprockets from 4.0.3 to 4.1.0 slows it down considerably, my system tests run about 15%-20% slower.
A bisect reveals that this commit is to blame: cdab3b8
Without that commit the performance of version 4.1.0 is identical to 4.0.3.
I think that the lower casing of the headers probably breaks caching somewhere?
The text was updated successfully, but these errors were encountered: