mirror of https://github.com/fafhrd91/actix-web
remove cloneable bench experiments + cargo fmt
This commit is contained in:
parent
6bb895365b
commit
ba76dfb2bb
|
@ -125,7 +125,3 @@ harness = false
|
||||||
[[bench]]
|
[[bench]]
|
||||||
name = "service"
|
name = "service"
|
||||||
harness = false
|
harness = false
|
||||||
|
|
||||||
[[bench]]
|
|
||||||
name = "cloneable"
|
|
||||||
harness = false
|
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
mod experiments;
|
|
||||||
mod service;
|
|
||||||
|
|
||||||
use actix_web::test::ok_service;
|
|
||||||
use criterion::{criterion_main, Criterion};
|
|
||||||
use experiments::cloneable::cloneable;
|
|
||||||
use experiments::cloneable::cloneable_safe;
|
|
||||||
use service::bench_async_service;
|
|
||||||
|
|
||||||
// This is benchmark of effect by replacing UnsafeCell to RefCell in CloneableService
|
|
||||||
// Issue: https://github.com/actix/actix-web/issues/1295
|
|
||||||
//
|
|
||||||
// Note: numbers may vary from run to run +-20%, probably due to async env
|
|
||||||
// async_service_direct time: [1.0076 us 1.0300 us 1.0507 us]
|
|
||||||
// change: [-32.491% -23.295% -15.790%] (p = 0.00 < 0.05)
|
|
||||||
// async_service_cloneable_unsafe
|
|
||||||
// time: [1.0857 us 1.1208 us 1.1629 us]
|
|
||||||
// change: [-2.9318% +5.7660% +15.004%] (p = 0.27 > 0.05)
|
|
||||||
// async_service_cloneable_safe
|
|
||||||
// time: [1.0703 us 1.1002 us 1.1390 us]
|
|
||||||
// change: [-9.2951% -1.1186% +6.5384%] (p = 0.80 > 0.05)
|
|
||||||
|
|
||||||
pub fn service_benches() {
|
|
||||||
let mut criterion: Criterion<_> = Criterion::default().configure_from_args();
|
|
||||||
bench_async_service(&mut criterion, ok_service(), "async_service_direct");
|
|
||||||
bench_async_service(
|
|
||||||
&mut criterion,
|
|
||||||
cloneable::CloneableService::new(ok_service()),
|
|
||||||
"async_service_cloneable_unsafe",
|
|
||||||
);
|
|
||||||
bench_async_service(
|
|
||||||
&mut criterion,
|
|
||||||
cloneable_safe::CloneableService::new(ok_service()),
|
|
||||||
"async_service_cloneable_safe",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
criterion_main!(service_benches);
|
|
|
@ -1,36 +0,0 @@
|
||||||
use std::cell::UnsafeCell;
|
|
||||||
use std::rc::Rc;
|
|
||||||
use std::task::{Context, Poll};
|
|
||||||
|
|
||||||
use actix_service::Service;
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
/// Service that allows to turn non-clone service to a service with `Clone` impl
|
|
||||||
pub(crate) struct CloneableService<T: Service>(Rc<UnsafeCell<T>>);
|
|
||||||
|
|
||||||
impl<T: Service> CloneableService<T> {
|
|
||||||
pub(crate) fn new(service: T) -> Self {
|
|
||||||
Self(Rc::new(UnsafeCell::new(service)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Service> Clone for CloneableService<T> {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
Self(self.0.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Service> Service for CloneableService<T> {
|
|
||||||
type Request = T::Request;
|
|
||||||
type Response = T::Response;
|
|
||||||
type Error = T::Error;
|
|
||||||
type Future = T::Future;
|
|
||||||
|
|
||||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
|
||||||
unsafe { &mut *self.0.as_ref().get() }.poll_ready(cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, req: T::Request) -> Self::Future {
|
|
||||||
unsafe { &mut *self.0.as_ref().get() }.call(req)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::rc::Rc;
|
|
||||||
use std::task::{Context, Poll};
|
|
||||||
|
|
||||||
use actix_service::Service;
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
|
||||||
/// Service that allows to turn non-clone service to a service with `Clone` impl
|
|
||||||
pub(crate) struct CloneableService<T: Service>(Rc<RefCell<T>>);
|
|
||||||
|
|
||||||
impl<T: Service> CloneableService<T> {
|
|
||||||
pub(crate) fn new(service: T) -> Self {
|
|
||||||
Self(Rc::new(RefCell::new(service)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Service> Clone for CloneableService<T> {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
Self(self.0.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Service> Service for CloneableService<T> {
|
|
||||||
type Request = T::Request;
|
|
||||||
type Response = T::Response;
|
|
||||||
type Error = T::Error;
|
|
||||||
type Future = T::Future;
|
|
||||||
|
|
||||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
|
||||||
self.0.borrow_mut().poll_ready(cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn call(&mut self, req: T::Request) -> Self::Future {
|
|
||||||
self.0.borrow_mut().call(req)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,2 +0,0 @@
|
||||||
pub mod cloneable;
|
|
||||||
pub mod cloneable_safe;
|
|
|
@ -1 +0,0 @@
|
||||||
pub mod cloneable;
|
|
Loading…
Reference in New Issue