Skip to content

Should simple-result-> stop using with-contract-continuation-mark ? #1292

Open
@bennn

Description

@bennn

The simple-result-> contract should maybe stop using with-contract-continuation-mark (wccm) to run as quickly as possible.

Here is one program where wccm adds zero benefit but has big costs. This program goes through some (-> any real?) contracts many times:

#lang typed/racket

(module uuu racket
  (struct posn (x y))
  (provide (struct-out posn)))

(require/typed 'uuu
  (#:struct posn ((x : Real) (y : Real))))

(define origin (posn 0 0))

(for ((i (in-range (expt 10 8))))
  (posn-x origin)
  (posn-y origin))

It takes about 6 seconds to run.

With unsafe-require/typed it takes <1 second.

Ok, so there's a big cost due to contracts. But, running raco contract-profile main.rkt on this program says 0% of the runtime is due to contracts. Each contract check is too fast for the sampler to see. Increasing the sampling rate does not seem to help. Getting rid of the simple-result-> optimization does help: 17.62% contracts.

With simple-result-> and without the wccm, the program takes about 5 seconds.

To sum up:

  • The contract profiler doesn't see the marks, but these marks cost about 1 second on this 6-second example.

So maybe the marks should be off by default and available on an opt-in basis.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions