Skip to content

Instantly share code, notes, and snippets.

ServerResultUtils.splitSetCookieHeaders (3.76%)

  • half of this is regex pattern matching
  • half is Scala collections overhead
  • SUGGESTION: replace flatMap with a while loop operating on the regex

ServerResultUtils.prepareCookies (12.9%) + CSRFAction$SignedTokenProvider.generateToken (7.43%) = 20.3%

  • change CSRF so we delay adding a cookie to the result until actually needed (i.e. when first used in a CSRF-protected form)
    • when receiving a request CSRF filter adds a CSRFToken object to request attribute
    • CSRFToken object's value is either read from the request or it's lazy - no data at first
  • when first read, e.g. by adding token to a form, lazily generates a value
benches/jmh:runMain scala.future.BenchRunner -i 2 -wi 2 -f1 -t1 .*
# Run complete. Total time: 00:10:58
Benchmark (impl) (result) Mode Cnt Score Error Units
CallbackBenchmark.onComplete_1 stdlib N/A thrpt 2 14.777 ops/us
CallbackBenchmark.onComplete_1 improved N/A thrpt 2 20.587 ops/us
CallbackBenchmark.onComplete_1 improved2 N/A thrpt 2 20.086 ops/us
CallbackBenchmark.onComplete_1024 stdlib N/A thrpt 2 42.248 ops/us
CallbackBenchmark.onComplete_1024 improved N/A thrpt 2 47.474 ops/us
@richdougherty
richdougherty / gist:cd983edd1fdfb31e0f718fa890eac08d
Created February 19, 2017 22:41
Omnidoc errors with Play WS
...
[info] Generating /p/play/omnidoc/deploy/omnidoc/target/scala-2.11/omnidoc/javadoc/play/libs/ws/StandaloneWSRequest.html...
[error] /p/play/omnidoc/deploy/omnidoc/target/scala-2.11/omnidoc/sources/com.typesafe.play-play-ws-standalone_2.11-1.0.0-M3/play/libs/ws/StandaloneWSRequest.java:244: warning: no @param for <U>
[error] <U> StandaloneWSRequest setBody(Source<ByteString, U> body);
[error] ^
[info] Generating /p/play/omnidoc/deploy/omnidoc/target/scala-2.11/omnidoc/javadoc/play/libs/ws/StandaloneWSResponse.html...
...
[info] Generating /p/play/omnidoc/deploy/omnidoc/target/scala-2.11/omnidoc/javadoc/play/libs/ws/WSRequestFilter.html...
[error] /p/play/omnidoc/deploy/omnidoc/target/scala-2.11/omnidoc/sources/com.typesafe.play-play-ws-standalone_2.11-1.0.0-M3/play/libs/ws/WSRequestFilter.java:12: error: unterminated inline tag
[error] * {@code
/**
* Handle the given request.
*/
def handle(channel: Channel, request: HttpRequest): Future[HttpResponse] = {
logger.trace("Http request received by netty: " + request)
import play.core.Execution.Implicits.trampoline
/** Convert a Play Result to a NettyResponse. */
@richdougherty
richdougherty / Inhabitation.txt
Last active April 12, 2016 04:28
Type inhabitation algorithm for Whiley
INHABITATION ALGORITHM
The idea is to label each state in a type's automaton with a ternary value to
indicate our knowledge about its inhabitation:
1. all - inhabited by all values (aka any)
2. none - inhabited by no values (aka void)
3. some - may be inhabited by some values
States with a basic type have an implicit label corresponding to the type:
@richdougherty
richdougherty / dawnbringer-16-color-palette.md
Last active January 27, 2016 23:30
Color names for the DawnBringer 16-color palette
@richdougherty
richdougherty / gist:fc721bf5944c29789d3c
Created December 14, 2015 22:57
Netty exceptions
This error happened on a branch based on master cf4bd63fb75eb31b28f345ece1b202546cc29f04.
Running wrk for two minutes we get a report of two read errors in the client. In the log we see two exceptions.
play ▶ [] ~/prune/manual-tests/apps-repo/scala-di-bench/target/universal/stage/logs$ less application.log
2015-12-14 14:54:06,793 [WARN] from application in main - Logger configuration in conf files is deprecated and has no effect. Use a logback configuration file instead.
2015-12-14 14:54:07,599 [WARN] from application in main - application.langs is deprecated, use play.i18n.langs instead
2015-12-14 14:54:07,687 [WARN] from application in main - application.conf @ file:/home/play/prune/manual-tests/apps-repo/scala-di-bench/target/universal/stage/conf/application.conf: 8: application.secret is deprecated, use play.crypto.secret instead
2015-12-14 14:54:07,821 [INFO] from play.api.Play in main - Application started (Prod)
2015-12-14 14:54:08,234 [INFO] from play.core.server.NettyServer in main - Listening for
class MyController @Inject() (injector: Injector) extends Controller { ... }
Scala Java
Option(x) Optional.ofNullable(x)
Option.empty[T] Optional.<T>empty()
None n/a (because Java doesn't have Nothing type)
Some(x) Optional.of(x)
Some(null) n/a (because Java Optional doesn't support null)